PHP - Use Of Minus With Xml
Hi
I'm using SimpleXMLElement to work with a supplied XML file, problem is with the way the XML document is formatted. The document uses '-' (minus) in the element names instead of _ so when I go to read the values, nothing is returned: Code: [Select] $developer->developer-region; //returns nothing However if I change the sample XML document that I've been supplied to <developer_region></developer_region> and do Code: [Select] $developer->developer_region; //returns child elements This is not practical to manually change the document, is there a way to use '-' in the xml document? Thanks in advance Ste Similar TutorialsHi Can someone point me in the right direction. I can force php to put a Plus(+) sign in front of positive numbers with printf('%0+4.2f',$x) But I cant get this to work inside <option>printf('%0+4.2f',$x)</option> tags Any help is greatly appreciated. hi , i want to select qty from master where id=$id , then i want to minus the qty = qty -1 and update in the query . here is my code . can tell me what went wrong ? Code: [Select] $query= "SELECT qty FROM master where id=$id"; $result = mysql_query($query,$dblink); while($myrow = mysql_fetch_row($result)) { qty -= 1; $query = "UPDATE master SET qty='$qty' WHERE id= $id"; $result = mysql_query($query,$dblink); } thanks Hi all I have a string called $voucher_code which is a value used to deduct or add value to a shopping cart. If the value is a minus I need it to show the minus sign, or if it's a plus value, it needs to show a plus sign. Here's my code: <strong>£ -".number_format(($voucher_code),2)."</strong> How do I modify the above code to show + instead of -- which it does at the moment? Many thanks for your help Pete Hey guys, Was wondering if someone could point me on the right path here. I am able to get the page URL using: $url = (!empty($_SERVER['HTTPS'])) ? "https://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'] : "http://".$_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI']; But was wondering if there was a way to drop the PHP variables attached to the URL. e.g. mysite.com/catalogue/?item=23 becomes mysite.com/catalogue/ Can anyone help me out? Thanks! Hello, I've been struggling for days on this problem now. And I'm getting frustrated! I know that the answer is simple, and I've done it before but I cannot figure out what I'm doing wrong. What do I want? Well, I get a date from the database in this format: YYYY-MM-DD. I first want to distract one month from that and then set in into this form: YYYY, MM, DD. I've got this but it's not working (I've tried a lot different values). $transformdate = date("Y-m-d", strtotime("-1 month", $d_datevalue)); $startpoint = str_replace("-", ", ", $transformdate); Thanks, NLCJ Hi all I'm building a script which reads a XML document, and so far so good... until now! the document uses '-' extensively all the way through it (not something that I would have chosen) so to combat this I've used {}. The part of the document I am working on now, this simply does not work, and I really cannot see why... XML Code: [Select] <plot> <name-number>87</name-number> <price>183000</price> <bedrooms>4</bedrooms> <status>available</status> <summary>With three double bedrooms, including one en suite and a further bedroom plus family bathroom to the first floor,&nbsp;separate lounge and&nbsp;dining room with kitchen&nbsp;and utility to the ground floor, the Otter is a modern home with a great deal to offer growing families.</summary> <feature>Separate lounge and dining room</feature> <feature>Kitchen with utility room</feature> <feature>Integral garage</feature> <feature>En suite to master bedroom</feature> <property-type>detached-house</property-type> <media> <caption> </caption> <type>image</type> <filename>1855_Otter-WhitehirstGrange.jpg</filename> <indexno>1</indexno> </media> <media> <caption> </caption> <type>floorplan</type> <filename>1386_Otter-WhitehirstGrange.pdf</filename> <indexno>2</indexno> </media> <media> <caption> </caption> <type>brochure</type> <filename>284_brochure.pdf</filename> <indexno>3</indexno> </media> <style-name>Otter</style-name> </plot> PHP Code: [Select] echo $plot->{name-number}; // echoes nothing, should echo 87 echo $plot->price; // echoes 183000 echo $plot->bedrooms // echoes 4 echo $plot->{style-name} // echoes nothing, should echo Otter This is frustrating the hell out of me, and I cannot see why this would work everywhere else in the XML document but not here. Any ideas or help would be received with gratitude! Hi, I'm having trouble with this: Code: [Select] $date = date('d/m/y') ; echo $date; echo "<br/>"; $date1 = strtotime('date -1 month'); echo date('Y-m-d', $date1); My result looks like this: Current Date: 19/05/11 Date minus 1 month: 1970-01-01 I want it to look like this: Current Date: 19/05/11 Date minus 1 month: 2011-04-19 Hi, I am a beginner with php and I am having a hard time understanding a section in my code. The part I dont get is why we have to minus 1 from the number being passed into the array. For example, $FaceNamePlural[$die1-1] I tried looking at it over and over but I'm still very confused. Can anyone help me on this...Thanks. Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>Untitled Document</title> </head> <body> <?php $FaceNameSingular = array("one", "two", "three", "four", "five", "six"); $FaceNamePlural = array("ones", "twos", "threes", "fours", "fives", "sixs"); function CheckForDoubles($die1, $die2) { global $FaceNameSingular; global $FaceNamePlural; if($die1 == $die2) // doubles echo "The roll was double ", $FaceNamePlural[$die1-1], "<br />"; if($die1 != $die2) //not doubles echo "The roll was a ", $FaceNameSingular[$die1-1], " and a ", $FaceNameSingular[$die2-1], ".<br />"; } function DisplayScoreText($Score) { if($Score == 2) echo "you roll snake eyes! <br />"; if($Score == 3) echo "you roll loose duece! <br />"; if($Score == 5) echo "you roll fever five! <br />"; if($Score == 7) echo "you roll natural! <br />"; if($Score == 9) echo "you roll nina! <br />"; if($Score == 11) echo "you roll yo! <br />"; if($Score == 12) echo "you roll boxcars! <br />"; } $dice = array(); $dice[0] = rand(1,6); $dice[1] = rand(1,6); $Score = $dice[0] + $dice[1] ; echo "<p>"; echo "The total score for the roll was $Score . <br />"; CheckForDoubles($dice[0],$dice[1]); DisplayScoreText($Score); echo "</p>"; ?> </body> </html> Hello $row[longdescription] contains a description of a product (complete with HTML mark-up). I would like to display the first 250 characters in the results of a search. I would also like to remove any images that may crop up. This is what I have so far... Code: [Select] echo strip_tags(html_entity_decode(substr(preg_replace('/<img[^>]*>/Ui', '', $row[longdescription]), 0, 250))); The thing is (as you guys can probably already see), it also counts the HTML mark-up as characters and I get very different outputs (especially if an image occurs). I'd appreciate if you could advise me as to the correct way of doing this. Thank you I insert a time value using the following code
$ti= ( !empty($_POST['time']) ) ? "'{$_POST['time']}'" : 'NULL';
I want to insert a second time value into a differen column which would be the same time minus 1 hour
something along the lines of :
$ti2= ( !empty($_POST['time']) ) ? "'{$_POST['time'] -1 hour}'" : 'NULL';
What would be the correct way to do it
|