Posts

Showing posts with the label print

How to quote in echo or print in PHP?

If you are creating applications in PHP, even if you are beginner, you definatelly see echo function already. Echo function just outputs it's argument to a user browser or to a console/terminal if PHP script is running in the CLI mode. The trouble rises, when you have to put ' or " sign in a echo, because you have to use one of this characters just to begin and terminate echo literal. To embed such characters in displayer string, you need to use escape sequence . It is a special characters combination, that makes some special sense in string literal. So, if you want to send quote sign to user, not to terminate echo string, use \" escape sequence. If your sequence is terminated by single quotes ('), then you can also include this character in string by escape sequence \'. See examples below: echo "This example shows \"escape sequences\" in php string, like quotes etc"; echo 'This example shows \'escape sequences\' in php string, ...

PHP Print state of a session

If you want to print all current variables stroed in session just use print_r function, as exaple shows: print_r( $_SESSION ); This will print all varaibles previously set in current session. Don't forget to call session_start() earlier to start a browser session

PHP Print array - how to show contents of an array

You can simple show entire contents of an array by callind print_r function: print_r($theArray); $arrayContents = print_r($theArray,true); Second example show how you can grab output to a variable to parse it or store somewhere (lika a file)