How can I get the first n characters of a string in PHP? What’s the fastest way to trim a string to a specific number of characters, and append ‘…’ if needed? Answer Update: Based on suggestion for checking length (and also ensuring similar lengths on trimmed and untrimmed strings): So you will get a string of max 13 characters;
Why is calling a function (such as strlen, count etc) on a referenced value so slow?
I’ve just found something very strange in PHP. If I pass in a variable to a function by reference, and then call a function on it, it’s incredibly slow. If you loop over the inner function call and the variable is large it can be many orders of magnitude slower than if the variable is passed by value. Example: This
How to reset indexes in array_diff result?
I have two arrays: Array ( [0] => 2 [1] => 3 ) and Array ( [0] => 2 ). I want to get the value, which is not in second array. So I have used the array_diff function but my result will get …
Fatal error: Call to undefined function: imagecreate()
I’m trying to put some graphics on a web page and at my prototype at the computer it’s all working fine at the localhost. But now I uploaded the files to a server and I’m having a problem to plot some graphics. In my computer they are plotted, but on the server they are not. I’m getting this error Fatal
Why do you not use C for your web apps? [closed]
I was having a look at a few different web servers this morning when I came across G-WAN. As I understand, its a web server written in C and you have to make use of it by writing your websites/webapps …
Set start and end date for last 30 days ending today
I need to generate two dates in the format YYYY-MM-DD example: 2010-06-09 The end date should be today and start date should be today – 30 days. How can I generate these 2 dates in the above format?
Convert PostgreSQL array to PHP array
I have trouble reading Postgresql arrays in PHP. I have tried explode(), but this breaks arrays containing commas in strings, and str_getcsv() but it’s also no good as PostgreSQL doesn’t quote the Japanese strings. Not working: Example: Answer If you have PostgreSQL 9.2 you can do something like this: The result will return the array as JSON Then on the
XDebug not working with xampp
I’m using (or trying to anyway) use the bundled XDebug with XAMPP 1.7.2. It comes bundled with Apache 2.2.12, PHP 5.3.0, XDebug 2.0.5 and Zend (not sure on version) This is a totally fresh install of XAMPP, the only thing I’ve added to php.ini (at xampp/php/php.ini) is: (this is only one of many different configs I’ve tried) But try as
Strip all non-alphanumeric, spaces and punctuation symbols from a string
How can I use PHP to strip out all characters that are NOT letters, numbers, spaces, or punctuation marks? I’ve tried the following, but it strips punctuation. Answer Example: p{P} matches all Unicode punctuation characters (see Unicode character properties). If you only want to allow specific punctuation, simply add them to the negated character class. E.g:
PHP – Redirect and send data via POST
I have an online gateway which requires an HTML form to be submitted with hidden fields. I need to do this via a PHP script without any HTML forms (I have the data for the hidden fields in a DB) To …