PHP - How To Parse A Value Into Several Variables
I am trying to take a value that is stored in a db for address and parse it into 4 different variables:
$address $city $state $zip when I started the loop and echo'd the results, here is how it comes out: Code: [Select] a:4:{s:14:"street_address";s:20:"811 East Parrish Ave";s:4:"city";s:9:"Owensboro";s:5:"state";s:2:"KY";s:3:"zip";s:5:"42303";} a:4:{s:14:"street_address";b:0;s:4:"city";b:0;s:5:"state";b:0;s:3:"zip";b:0;} a:4:{s:14:"street_address";s:15:"800 Rose Street";s:4:"city";s:9:"Lexington";s:5:"state";s:2:"KY";s:3:"zip";s:5:"40536";} a:4:{s:14:"street_address";s:19:"1300 State Hwy 3298";s:4:"city";s:10:"Olive Hill";s:5:"state";s:2:"KY";s:3:"zip";s:5:"41164";} a:4:{s:14:"street_address";s:22:"1301 North Race Street";s:4:"city";s:7:"Glasgow";s:5:"state";s:2:"KY";s:3:"zip";s:5:"42141";} a:4:{s:14:"street_address";s:23:"200 Abraham Flexner Way";s:4:"city";s:10:"Louisville";s:5:"state";s:2:"KY";s:3:"zip";s:5:"40202";} Similar TutorialsI have been playing with XML and PHP, I have googled to get the requirement which I am working on but still Im not getting the things the way I wanted. I have got a XML file with nested variables, I need to parse the variables such as user_id, name and store it in an array, so that I need to use them to change the details in another config file. For ex: if the user is logged in, using the user_id, i need to parse the all the data of the particular user from the XML file (where the details of the various users are stored). Until now I could only parse the data and echo all of it but could not find a way to store this parsed information. This is my "test.xml" file: Code: [Select] <?xml version="1.0" encoding="ISO-8859-1"?> <document> <user> <user_id>0121</user_id> <name>Tim</name> <file>0121.file</file> </user> <user> <user_id>0178</user_id> <name>Henry</name> <file>0178.file</file> </user> <user> <user_id>0786</user_id> <name>Martin</name> <file>0786.file</file> </user> <user> <user_id>1239</user_id> <name>Jan</name> <file>1239.file</file> </user> </document> Any valuable information would be greatly helpful Thanks Raaks hi all am new to this forum help me to overcome from this error Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in D:\wamp\www\quiz1\quiz1.php on line 12 Code: [Select] <?php include("contentdb.php"); $display = mysql_query("SELECT * FROM $table ORDER BY id",$db); if (!$submit) { echo "<form method=post action=$_SERVER['PHP_SELF']>"; echo "<table border=0>"; while ($row = mysql_fetch_array($display)) { $id = $row["id"]; $question = $row["question"]; $opt1 = $row["opt1"]; $opt2 = $row["opt2"]; $opt3 = $row["opt3"]; $answer = $row["answer"]; echo "<tr><td colspan=3><br><b>$question</b></td></tr>"; echo "<tr><td>$opt1 <input type=radio name=q$id value=\"$opt1\"></td><td>$opt2 <input type=radio name=q$id value=\"$opt2\"></td><td>$opt3 <input type=radio name=q$id value=\"$opt3\"></td></tr>"; } echo "</table>"; echo "<input type='submit' value='See how you did' name='submit'>"; echo "</form>"; } elseif ($submit) { $score = 0; $total = mysql_num_rows($display); while ($result = mysql_fetch_array($display)) { $answer = $result["answer"]; $q = $result["q"]; if ($$q == $answer) { $score++; } } echo "<p align=center><b>You scored $score out of $total</b></p>"; echo "<p>"; if ($score == $total) { echo "Congratulations! You got every question right!"; } elseif ($score/$total < 0.34) { echo "Oh dear. Not the best score, but don't worry, it's only a quiz."; } elseif ($score/$total > 0.67) { echo "Well done! You certainly know your stuff."; } else { echo "Not bad - but there were a few that caught you out!"; } echo "</p>"; echo "<p>Here are the answers:"; echo "<table border=0>"; $display = mysql_query("SELECT * FROM $table ORDER BY id",$db); while ($row = mysql_fetch_array($display)) { $question = $row["question"]; $answer = $row["answer"]; $q = $row["q"]; echo "<tr><td><br>$question</td></tr>"; if ($$q == $answer) { echo "<tr><td>»you answered ${$q}, which is correct</td></tr>"; } elseif ($$q == "") { echo "<tr><td>»you didn't select an answer. The answer is $answer</td></tr>"; } else { echo "<tr><td>»you answered ${$q}. The answer is $answer</td></tr>"; } } echo "</table></p>"; } ?> thanks in adavance Hello I have one problem with fwrite() I have one script to get width and height from javascript and echo it with PHP. echo "Screen width is: ". $_GET['width'] ."<br />\n"; echo "Screen height is: ". $_GET['height'] ."<br />\n"; It works but i want to store the result in a file fwrite($info,"Height: $_GET['height'] <br />"); But then I get error Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING //////////////////////// it would be even better if I don't have to print the values but directly store them in $iinfo sorry if something similar was soved but those examples were different or i was unable to transform it to solve my problem I am trying to put a href on a line to link me to another php module, but get an error: Parse error: parse error in C:\wamp\www\editpolicy.php on line 47 My code: while ($row2 = mysql_fetch_array($result2) ) { print "<tr><td>"; <a href='editpayment.php?payid=$row2[PaymentID]'>$row2[PaymentID]</a> .........THIS IS LINE 47 ??? print "</td><td>"; print $row2['Actioned']; print "</td><td align='right'>"; print $row2['PremiumPaidAmount']; print "</td><td align='right'>"; print $row2['Risk']; print "</td></tr>"; } echo "</select></td>\r\n </tr>\r\n \r\n <tr>\r\n <td align=\"right\">Total Views Allowed:</td>\r\n <td><input type=\"text\" id=\"ad_total_views\" style=\"width:50px;\" value=\"\" disabled=\"disabled\" /> <label><input type=\"checkbox\" checked=\"checked\" onclick=\"if(this.checked==true){$('#ad_total_views').val('');$('#ad_total_views').attr('disabled','disabled');}else{$('#ad_total_views').val('');$('#ad_total_views').removeAttr('disabled');$('#ad_total_views').focus()}\" />Unlimited</label></td>\r\n </tr>\r\n \r\n <tr>\r\n <td align=\"right\">Total Clicks Allowed:</td>\r\n <td><input type=\"text\" id=\"ad_total_clicks\" style=\"width:50px;\" value=\"\" disabled=\"disabled\" /> <label><input type=\"checkbox\" checked=\"checked\" onclick=\"if(this.checked==true){$('#ad_total_clicks').val('');$('#ad_total_clicks').attr('disabled','disabled');}else{$('#ad_total_clicks').val('');$('#ad_total_clicks').removeAttr('disabled');$('#ad_total_clicks').focus()}\" />Unlimited</label></td>\r\n </tr>\r\n </table></td>\r\n </tr>\r\n <tr bgcolor=\"#FFFFFF\">\r\n <td class=\"td_th\" align=\"center\">Smarty Code (Developer)</td>\r\n <td>{\$ads->getAdCode(<span id=\"smartycode\">1</span>)}</td>\r\n </tr>\r\n <tr bgcolor=\"#FFFFFF\">\r\n <td class=\"td_th\" align=\"center\"> </td>\r\n <td><input type=\"button\" value=\"Create New Campaign\" onclick=\"new_ad()\" /></td>\r\n </tr>\r\n </TBODY></TABLE>\r\n<br />\r\n\r\n<TABLE cellSpacing=1 cellPadding=4 width=\"100%\" border=0>\r\n <TBODY>\r\n <TR class=\"td_title\">\r\n <TD colSpan=7>Ad Campaigns</TD></TR>\r\n <TR bgColor=#ffffff>\r\n \r\n <TD width=\"10%\" align=\"center\" class=\"td_th\"> </TD>\r\n <TD width=\"4%\" align=\"center\" class=\"td_th\">ID</TD>\r\n <TD width=\"29%\" align=\"center\" class=\"td_th\">Campaign Name</TD>\r\n <TD width=\"12%\" align=\"center\" class=\"td_th\">Start Date</TD>\r\n <TD width=\"11%\" align=\"center\" class=\"td_th\">End Date</TD>\r\n <TD width=\"17%\" align=\"center\" class=\"td_th\">Viewed / Views Allowed</TD>\r\n <TD width=\"17%\" align=\"center\" class=\"td_th\">Clicked / Clicks Allowed</TD>\r\n </TR>\r\n "; $BoxSize = array("smallbox" = array("length" => 12, "width" => 10, "depth" => 2.5), "mediumbox" = array("length" => 30, "width" => 20, "depth" => 4), "largebox" = array("length" => 60, "width" => 40, "depth" => 11.5)); does anyone know how to decode this XML variable value into string values? I also need to know the oposite way: creating variable values into xml. I've tried several code examples but they did filter the requested data. Code: [Select] $xml='<?xml version="1.0" encoding="utf-8"?> <elements> <text identifier="ed9cdd4c-ae8b-4ecb-bca7-e12a5153bc02"> <value/> </text> <textarea identifier="a77f06fc-1561-453c-a429-8dd05cdc29f5"> <value><![CDATA[<p style="text-align: justify;">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>]]></value> </textarea> <textarea identifier="1a85a7a6-2aba-4480-925b-6b97d311ee6c"> <value><![CDATA[<p style="text-align: justify;">Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit amet.</p>]]></value> </textarea> <image identifier="ffcc1c50-8dbd-4115-b463-b43bdcd44a57"> <file><![CDATA[images/stories/red/cars/autobedrijf.png]]></file> <title/> <link/> <target/> <rel/> <lightbox_image/> <width><![CDATA[250]]></width> <height><![CDATA[187]]></height> </image> <text identifier="4339a108-f907-4661-9aab-d6f3f00e736e"> <value><![CDATA[Kramer 5]]></value> </text> <text identifier="ea0666d7-51e3-4e52-8617-25e3ad61f8b8"> <value><![CDATA[6000 RS]]></value> </text> <text identifier="90a18889-884b-4d53-a302-4e6e4595efa0"> <value><![CDATA[Eindhoven]]></value> </text> <text identifier="410d72e0-29b3-4a92-b7d7-f01e828b1586"> <value><![CDATA[APK Pick up and return]]></value> </text> <text identifier="45b86f23-e656-4a81-bb8f-84e5ea76f71f"> <value><![CDATA[15% korting op grote beurt]]></value> </text> <text identifier="3dbbe1c6-15d6-4375-9f2f-f0e7287e29f3"> <value><![CDATA[Gratis opslag zomerbanden]]></value> </text> <text identifier="2e878db0-605d-4d58-9806-8e75bced67a4"> <value><![CDATA[Gratis abonnement of grote beurt]]></value> </text> <text identifier="94e3e08f-e008-487b-9cbd-25d108a9705e"> <value/> </text> <text identifier="73e74b73-f509-4de7-91cf-e919d14bdb0b"> <value/> </text> <text identifier="b870164b-fe78-45b0-b840-8ebceb9b9cb6"> <value><![CDATA[040 123 45 67]]></value> </text> <text identifier="8a91aab2-7862-4a04-bd28-07f1ff4acce5"> <value/> </text> <email identifier="3f15b5e4-0dea-4114-a870-1106b85248de"> <value/> <text/> <subject/> <body/> </email> <link identifier="0b3d983e-b2fa-4728-afa0-a0b640fa34dc"> <value/> <text/> <target/> <custom_title/> <rel/> </link> <relateditems identifier="7056f1d2-5253-40b6-8efd-d289b10a8c69"/> <rating identifier="cf6dd846-5774-47aa-8ca7-c1623c06e130"> <votes><![CDATA[1]]></votes> <value><![CDATA[1.0000]]></value> </rating> <googlemaps identifier="160bd40a-3e0e-48de-b6cd-56cdcc9db892"> <location><![CDATA[50.895711,5.955427]]></location> </googlemaps> </elements>'; Code: [Select] This is a clip of my PHP file: <?php $con = mysql_connect($host,$username,$password); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database, $con); $result = mysql_query("SELECT * FROM purchase_order WHERE purchase_order_number=='$purchase_order_number'"); while($row = mysql_fetch_array($result)) { $vendor=$row['vendor']; $purchase_order_date=$row['purchase_order_date']; $ship=$row['ship']; $state=$row['state']; $fob=$row['fob']; $terms=$row['terms']; $buyer=$row['buyer']; $freight=$row['freight']; $req_date=$row['req_date']; $confirming_to=$row['confirming_to']; $remarks=$row['remarks']; $tax=$row['tax'] } // [i][u][b]<-- This is line 88 (The one with the error)[/b][/u][/i] ?>Thanks in advance! Hi. I have some code which needs to return a single variable from the function and stored as a variable within this page, so it can be echoed later on in the page. I couldn't get it to return as a variable, so i used "return compact();" to return the variable and "extract (myFunction());" to extract it to variables. However, when I turned on php's display errors and error reporting function, I got an error message saying "Warning: extract() [function.extract]: First argument should be an array in /my/web/site/index.php on line 6" (which is where my extract function is). This works fine with passing more than one variables through, is there another way pass one variable from a function to be stored as a variable on the page which called the function? Here is the function: Code: [Select] <?php //This is a list of numeric error codes against their text. this will return the error code as the variable $issue function checkLoginIssue() { //If there is an error code if (isset($_GET["issue"])) { //cycle through the list until the code is reached, return the text and break the switch switch ($_GET["issue"]) { case "1": $issue = '<p class="warning">Please log in to view this page</p>'; break; case "2": $issue = '<p class="warning">Wrong Username or Password</p>'; break; case "3": $issue = '<p class="warning">No user found with those details</p>'; break; } //return the variable in an array with a single value return compact('issue'); } } ?> And here is the code which calls the function: Code: [Select] <?php extract(checkLoginIssue()); ?> Can any one tell me how to access the image of this xml file: Code: [Select] <item> <title>DSC00083</title> <link>http://www.flickr.com/photos/53764782@N08/4963929579/</link> <description><p><a href="http://www.flickr.com/people/53764782@N08/">SteveDupree</a> posted a photo:</p> <p><a href="http://www.flickr.com/photos/53764782@N08/4963929579/" title="DSC00083"><img src="http://farm5.static.flickr.com/4111/4963929579_3334de3f06_m.jpg" width="240" height="180" alt="DSC00083" /></a></p></description> <pubDate>Mon, 06 Sep 2010 10:05:37 -0700</pubDate> <dc:date.Taken>2007-08-08T19:30:20-08:00</dc:date.Taken> <author flickr:profile="http://www.flickr.com/people/53764782@N08/">nobody@flickr.com (SteveDupree)</author> <guid isPermaLink="false">tag:flickr.com,2004:/photo/4963929579</guid> <media:content url="http://farm5.static.flickr.com/4111/4963929579_cf0b5e5656_o.jpg" type="image/jpeg" height="1224" width="1632"/> <media:title>DSC00083</media:title> <media:thumbnail url="http://farm5.static.flickr.com/4111/4963929579_3334de3f06_s.jpg" height="75" width="75" /> <media:credit role="photographer">SteveDupree</media:credit> </item> I am retereiving the title and the href with this: //print_r ($rss); echo '<ul>'; foreach ($rss->items as $item) { $href = $item['link']; $title = $item['title']; $img = $item['?????????']; echo "<li><a href=$href>" . $img . "</a></li>"; } echo "</ul>"; ?> but cant seem to get at Code: [Select] <media:content url="http://farm5.static.flickr.com/4111/4963929579_cf0b5e5656_o.jpg" type="image/jpeg" height="1224" width="1632"/> Hi,
I'm trying to return the value of avail="0" from the following XML file using simplexml_load_string.
<response> <result code="1000"> <msg>Command completed successfully</msg> </result> <resData> <domain:chkData xmlns:domain="urn:ietf:params:xml:ns:domain-1.0" xsi:schemaLocation="urn:ietf:params:xml:ns:domain-1.0 domain-1.0.xsd"> <domain:cd> <domain:name avail="0">www.testing.co.uk</domain:name> </domain:cd> </domain:chkData> </resData>I have it working where I can access the www.testing.co.uk value using the following: echo $xml->response->resData->children('domain', true)->chkData->children('domain', true)->cd->children('domain', true)->name;But am not sure how to access the avail value? I thought the following would have worked by adding ['avail'] onto the end, but appear to be missing something. echo $xml->response->resData->children('domain', true)->chkData->children('domain', true)->cd->children('domain', true)->name['avail'];Any help much appreciated. MoFish Hey guys I really need this done and am not experienced in php. I need to read this xml file h t t p : / / britishinternettv.co.uk/vlc.xml i need to extract the first url between -<url>and </url> this then needs to be echo'd (written) where i need it on my page. this must work afresh each page load. can donate to paypal if needed. thanks in advance Dennis Hi there, just wondering if anyone could cast there eyes over this, my error is
Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ',' or ';' on line 197
this is line 197 of the file with the error,
<input type="text" class="form-control" name="dob" id="dob" value="<?=(new DateTime($member['dob']))->format("d/m/Y");?>">
This was working not sure what has happend?
Thanks for your help
Rich
Writing a php script to select data from mysql data base and populate a html table. continue getting the following message Parse error: syntax error, unexpected T_LNUMBER in /home/chewson1/public_html/nurse_certification/dept_rpt.php on line 11 code is: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 3 <html xmlns="http://www.w3.org/1999/xhtml"> 4 <head> 5 <title>DEPARTMENT REPORT</title> 6 </head> 7 <body> 8 9 <?php 10 11 include_once('connectvars.php'); 12 $dbc = mysqli_connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) 13 or die('Error connecting to MySQL server.'); 14 15 $query = "SELECT cr_id, cr_empl_num, cr_ci_num, cr_cert_exp_dte, cr_flag, ci_num, ci_desc, ci_authority, ce_dpt, ce_name, ce_email, ce_phone_ext, ce_empl_num, cd_email, cd_num 16 FROM certification_record, certification_info, certification_employee, cert_department 17 WHERE cr_empl_num = ce_empl_num 18 AND ce_dpt = cd_num 19 AND cr_ci_num = ci_num 20 AND cr_flag > '00'"; 21 22 23 $result = mysqli_query($dbc, $query) 24 or die('ERROR querying database'); 25 ?> 26 27 <table border=1 style="background-color:#F0F8FF;"> 28 <caption><EM>Nurse Certification Report</EM></caption> 29 <tr> 30 <th>Department Number</th> 31 <th>Employeer Number</th> 32 <th>Employee Name</th> 33 <th>Employeer Email</th> 34 <th>Employeer Phone Extention</th> 35 36 </tr> 37 38 <?php 39 40 WHILE ($row = mysqli_fetch_assoc($result)) { 41 echo "</td><td>"; 42 echo $row['ce_dpt']; 43 echo "</td><td>"; 44 echo $row['ce_empl_num']; 45 echo "</td><td>"; 46 echo $row['ce_name']; 47 echo "</td></tr>"; 48 echo $row['ce_email']; 49 echo "</td><td>"; 50 echo $row['ce_phone_ext']; 51 echo "</td><td>"; 52 } 53 echo "</table>"; 54 55 56 ?> 57 58 </body> 59 </html> 60 I'm getting the following error when the $query = mysql_query line runs: Parse error: syntax error, unexpected T_VARIABLE Code: [Select] $vidtitle = strip_tags(trim($_POST['vidtitle'])); $viddesc = strip_tags(trim($_POST['viddesc'])); $vidtags = strip_tags(trim($_POST['vidtags'])); $vidurl = strip_tags(trim($_POST['vidurl'])); // get current username $username = $_SESSION['Username'] // register user $query = mysql_query("INSERT INTO haas12_test.videos (vidtitle, viddesc, vidtags, vidurl, username) VALUES('".$vidtitle."', '".$viddesc."', '".$vidtags."', '".$vidurl."', '".$username."')"); it worked fine before I added the username variables. Hi guys, I keep getting the following error: [22-Nov-2010 19:31:01] PHP Parse error: syntax error, unexpected ';', expecting T_STRING or T_VARIABLE or '{' or '$' in /home/meetano1/public_html/smartway/lib/system.lib(317) : eval()'d code on line 1 Here is my code: function parseVariables($file, $echo = 1) { $handle = fopen($file, "r"); if(!$handle) { return; } $content = fread($handle, filesize($file)); fclose($handle); $body = $content; for($ptr = 0; $ptr < strlen($body); $ptr++) { switch($body[ $ptr ]) { case "{": { $is_token = 1; $token = ""; break; } case "}": { $is_token = 0; eval("global \$".strtolower((strpos($token, "[") ? substr($token, 0, strpos($token, "[")) : $token)).";"); eval("\$sVal = \"$".strtolower($token)."\";"); $content = str_replace("{{$token}}", "$sVal", $content); $token = ""; break; } } if(($body[ $ptr ] != "{" && $body[ $ptr ] != "}") && $is_token) { $token .= $body[ $ptr ]; } } if($echo) echo $content; else return $content; } I was wondering what could be causing the error. Line 317 is: eval("global \$".strtolower((strpos($token, "[") ? substr($token, 0, strpos($token, "[")) : $token)).";"); Thanks in advance. this xml_parse_into_struct($iP=xml_parser_create(), curl_exec($ch), $bR, $bJ);xml_parser_free($iP); echo "::: ".strip_tags(str_replace("<br>","\n",$bR[$bJ['MESSAGE'][0]]['value']))."\n"; or... $xml = simplexml_load_string(curl_exec($ch)); foreach($xml->xml as $message){ echo strip_tags($message->message)."\n";} Just want to know which of these two would execute faster and if there was a better way that would be faster than both of these options? Thanks Hello this url https://www.googleapis.com/buzz/v1/people/sportsstatus/@groups/@followers?max-results=0 return an xml . I need to parse <totalResults> </totalResults> out of this feed using php .I need to retrieve data for the <totalresults> field. Iam stuck with this could not move further as iam new to php. I have been getting a parse error on my code. Any thoughts as to why? echo "<div id='memberContent'> <div id='welcome'> Welcome, \".$r['firstname'].\"! </div><br> <div class='profileImage'> <img src=\"assets/img/avatars/.$r['imagename']\" alt=\"Profile Picture\" height=\"90px\" title=\"$firstname.' '.$lastname\" /> </div> <div id='addfriend'> <a href='request.php'>Connect</a> </div> </div> "; Hi, I have a code which uses GET to retrieve data from the URL, check that it does not already exist in my database, then insert it into the database if it does not already exist, Problem is I am getting a Parse error: syntax error, unexpected T_STRING in /home/******/public_html/**-********/forums/like.php on line 12. Here is the code: Quote <? $username=$_GET['UN']; $postid=$_GET['PID']; mysql_connect("localhost", "*******", "***********") or die(mysql_error()); mysql_select_db("**********") or die(mysql_error()); $query_multiplecheck = "SELECT * FROM data WHERE username='$username' OR postid='$postid'; $multiplecheck = mysql_query($query_multiplecheck) or die(mysql_error()); $row_multiplecheck = mysql_fetch_assoc($multiplecheck); $totalRows_multiplecheck = mysql_num_rows($multiplecheck); if ( $totalRows_multiplecheck > 0 ) { echo 'You already like this post.'; } else { mysql_query("INSERT INTO data VALUES ('$username', '$postid')"); Print "Your information has been successfully added to the database."; }; ?> I would assume the problem is with my if statement, but I don't know exactly, thanks for any help in advance. |