June 27, 201115 yr Php explode not working on wamp <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Simple Two Col</title> <link rel="stylesheet" type="text/css" href="style.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript" src="prototype.js"></script> <script type="text/javascript" src="HelpBalloon.js"></script> </head> <body> <? $rawPhoneNumber = "800-555-5555"; $phoneChunks = explode("-", $rawPhoneNumber); echo "Raw Phone Number = $rawPhoneNumber <br />"; echo "First chunk = $phoneChunks[0]<br />"; echo "Second chunk = $phoneChunks[1]<br />"; echo "Third Chunk chunk = $phoneChunks[2]"; ?> </body> </html>
June 27, 201115 yr Php explode not working on wamp <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Simple Two Col</title> <link rel="stylesheet" type="text/css" href="style.css" /> <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript" src="prototype.js"></script> <script type="text/javascript" src="HelpBalloon.js"></script> </head> <body> <? $rawPhoneNumber = "800-555-5555"; $phoneChunks = explode("-", $rawPhoneNumber); echo "Raw Phone Number = $rawPhoneNumber <br />"; echo "First chunk = $phoneChunks[0]<br />"; echo "Second chunk = $phoneChunks[1]<br />"; echo "Third Chunk chunk = $phoneChunks[2]"; ?> </body> </html> What exactly is not working? Because not even looking more thoroughly: depending on configuration of Apache/PHP it might not recognize your opening/closing php tags, why don't you use <?php ?> Try cleaning up a little and see if it works: <?php $rawPhoneNumber = "800-555-5555"; $phoneChunks = explode("-", $rawPhoneNumber); echo ("Raw Phone Number = " . $rawPhoneNumber . " <br />"); echo ("First chunk = " . $phoneChunks[0] . "<br />"); echo ("Second chunk = " . $phoneChunks[1] . "<br />"); echo ("Third Chunk chunk = " . $phoneChunks[2]); ?> Edited June 27, 201115 yr by neverminder
June 27, 201115 yr Assuming $phoneChunks = explode("-", $rawPhoneNumber);die(var_dump($phoneChunks)) gives you an array its because your using array values in a string tis all... you can use the curly brackets to use array values in double quoted strings $phoneChunks = explode("-", $rawPhoneNumber); echo "Raw Phone Number = $rawPhoneNumber <br />"; echo "First chunk = {$phoneChunks[0]}<br />"; echo "Second chunk = {$phoneChunks[1]}<br />"; echo "Third Chunk chunk = {$phoneChunks[2]}"; Edited June 27, 201115 yr by SniderDK
June 27, 201115 yr Author What exactly is not working? Because not even looking more thoroughly: depending on configuration of Apache/PHP it might not recognize your opening/closing php tags, why don't you use <?php ?> Try cleaning up a little and see if it works: <?php $rawPhoneNumber = "800-555-5555"; $phoneChunks = explode("-", $rawPhoneNumber); echo ("Raw Phone Number = " . $rawPhoneNumber . " <br />"); echo ("First chunk = " . $phoneChunks[0] . "<br />"); echo ("Second chunk = " . $phoneChunks[1] . "<br />"); echo ("Third Chunk chunk = " . $phoneChunks[2]); ?> thanks that worked
June 27, 201115 yr this isn't a big thing, but if your not putting variables right into the string then using single quotes is the correct string encapsulation. echo ("First chunk = {$phoneChunks[0]}<br />"); // or echo ('First chunk = ' . $phoneChunks[0] . '<br />'); both work of course but in different ways in PHP
Create an account or sign in to comment