At the time of writing this, the smarty.net website appears to be down. Anyway, how do I replace line breaks with a space in a smarty variable? Is it something like this {$var|regex_replace:'[\r\n]…
php pchart pie chart problem with 0 value
I have a problem with my pie chart when I have 0 values $MyData->addPoints(array(10,20,20,15,23),”Data”); This works fine and converts to percentages across a pie chart however if any of these values are 0 which could happen as I’m dealing with counts and these are really variables in my …
socket connection code of php
I am writing a simple php socket code. Here is my code <?php $address="127.0.0.1"; $port=9875; echo "I am here"; if(false==($socket= socket_create(AF_INET,SOCK_STREAM, SOL_TCP))…
Pretty-Printing JSON with PHP
I’m building a PHP script that feeds JSON data to another script. My script builds data into a large associative array, and then outputs the data using json_encode. Here is an example script: The above code yields the following output: This is great if you have a small amount of data, but I’d pref…
How to set timeout for get_meta_tags() & get_headers()
I’ve been using the get_meta_tags() & get_headers() PHP functions, and need to set a timeout value in case the website is slow or unresponsive. Does anyone know how to do it?
How do I ignore a moved-header with file_get_contents in PHP?
I have programmed a simple content-user, that uses file_get_contents, but unfortunately for my IP the site now gives a 302 error that forwards to an image. For all other users the normal site is …
What are the backticks “ called?
What are the backtick operators (“) called in the context of evaluating their content? Answer If you’re referring to Bash then the backticks are known as “command substitution”. $() provides similar functionality.
PHP XSS sanitization
Questions: What are the best safe1(), safe2(), safe3(), and safe4() functions to avoid XSS for UTF8 encoded pages? Is it also safe in all browsers (specifically IE6)? . Many people say the absolute best that can be done is: . . There are a hell of a lot of posts about PHP and XSS. Most just say “use HTM…
PHPExcel very slow – ways to improve?
I am generating reports in .xlsx using PHPExcel. It was okay in the initial testing stages with small data sets (tens of rows, 3 sheets), but now when using it on a real production data with over 500 rows in each sheet, it becomes incredibly slow. 48 seconds to generate a file, and when running a report that …
Best way to give a variable a default value (simulate Perl ||, ||= )
I love doing this sort of thing in Perl: $foo = $bar || $baz to assign $baz to $foo if $bar is empty or undefined. You also have $foo ||= $bletch which will only assign $bletch to $foo if $foo is not defined or empty. The ternary operator in this situation is tedious and tiresome. Surely there’s a simpl…