ToString() equivalent in PHP How do I convert the value of a PHP variable to string? I was looking for something better than concatenating with an empty string: $myText = $myVar . ''; Like the ToString() method in Java or .NET. Answer: Can use the casting operators: $myText = (string)$myVar; There are more details for string casting and conversion in the Strings section of the PHP manual, including special handling for booleans and nulls.
undefined
How can I merge PHP arrays? I have two arrays of animals (for example). $array = array( array( 'id' => 1, 'name' => 'Cat', ), array( 'id' => 2, 'name' => 'Mouse', ) ); $array2 = array( array( 'id' => 2, 'age' => 321, ), array( 'id' => 1, 'age' => 123, ) ); How can I merge the two arrays into one by the ID? Answer: This does what Erik suggested (id no. as array key) and merges vlaues in $array2 to $results. $results =
undefined
Convert HTML + CSS to PDF with PHP? I'm now banging my head against a brick wall with this one. I have an HTML (not XHTML) document that renders fine in Firefox 3 and IE 7. It uses fairly basic CSS to style it and renders fine in HTML. I'm now after a way of converting it to PDF. I have tried: DOMPDF: it had huge problems with tables. I factored out my large nested tables and it helped (before it was just
undefined
undefined
How can I prevent SQL injection in PHP? If user input is inserted without modification into an SQL query, then the application becomes vulnerable to SQL injection, like in the following example: $unsafe_variable = $_POST['user_input']; mysql_query("INSERT INTO `table` (`column`) VALUES ('$unsafe_variable')"); That's because the user can input something like value'); DROP TABLE table;--, and the query becomes: INSERT INTO `table` (`column`) VALUES('value'); DROP TABLE table;--') What can be done to prevent this from happening? Answer: Use prepared statements and parameterized queries. These are SQL statements that
undefined
How can I find unused functions in a PHP project How can I find unused functions in a PHP project? Are there features or API's built into PHP that will allow me to analyse my codebase - for example Reflection, token_get_all()? Are these API's feature rich enough for me not to have to rely on a third party tool to perform this type of analysis? Answer : Thanks Greg and Dave for the feedback. Wasn't quite what I was looking for, but I decided to