<?php $str = "Test's"; echo stripslashes($str); //Test's ?>
Category Archives: PHP
Converts characters to HTML entities – PHP
<?php $str = "<p>First Name</p>"; echo htmlentities($str); //<p>First Name</p> ?>
Randomizes the order of the elements in an array – PHP
$numbers = range(0, 9); shuffle($numbers); foreach ($numbers as $number) { echo $number; }
Create an array containing a range of elements – PHP
<?php $numbers = range(0, 9); foreach($numbers as $value) echo $value." "; //Will output 0 1 2 3 4 5 6 7 8 9 ?>
Read Buffers – PHP
<?php ob_get_contents(); ?>
How to set default time zone – PHP
<?php date_default_timezone_set('America/Los_Angeles'); ?>
Reverse the order of elements in an array – PHP
<?php $testData= array('Test1', 'Test2', 'Test3'); print_r(array_reverse($testData)); //Array ( [0] => Test3 [1] => Test2 [2] => Test1 ) ?>
Find the last element of an array – PHP
<?php $testData= array('Test1', 'Test2', 'Test3'); echo end($testData); // Test3 ?>
How to convert string with delimiter into array – PHP
<?php // Example 1 $testValues = "test1 test2 test3 test4 test5"; $testArray = explode(" ", $testValues); print_r($testArray); //Array ( [0] => test1 [1] => test2 [2] => test3 [3] => test4 [4] => test5 ) // Example 2 $testValues = "test1,test2,test3,test4,test5"; $testArray = explode(",", $testValues); print_r($testArray); //Array ( [0] => test1 [1] => test2 [2] => test3 [3] => test4 [4] => test5 ) ?>
Convert array into string – PHP
<?php $testArray = array('Test1', 'Test2', 'Test3'); $testString = implode(",", $testArray); echo $testString; // Test1,Test2,Test3 ?>