PHP - $element->{name-with-minus} Being Completely Ignored
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! 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'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 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 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, 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 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 $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
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> Hi, I am having serious issues with compatibility with IE7 and below (and even 8 but they should be rectified). There is no way I can have these problems finished before the site is online, so I want to redirect users to a page apologizing and recommending alternative browsers. Is this possible? *Please don't reply just to tell me that banning an entire browser is bad, I know it is - I plan to sort it out. But this is an extra curricular project and I'm halfway through my penultimate year of uni, so IE and it's utterly shambolic rendering of CSS is not my priority. Thankyou* I'm brand new to PHP - trying to have a form that accepts a document attachment -
the top of my form has includes which a
include_once('/usr/bin/pear-stable/Mail.php'); Hi there, I am hoping someone here can help me with my problem... I have created some php code that I thought would do what I require but it just will not work! What I require is to connect to my database and get information from one table to see if a video has been marked as featured, if so then get some more information from that table and then get the users "NickName" from another table to show with the video screenshot. I have tried playing around with the code to see if I can get it to work but I have not been able to. Here is my code so far: mysql_connect("localhost", "*****", "*****") or die(mysql_error()); mysql_select_db("*****") or die(mysql_error()); $dir = "*****/*****/*****/"; $sql = "SELECT RayVideoFiles.ID, RayVideoFiles.Owner, RayVideoFiles.Views, RayVideoFiles.Featured, RayVideoFiles.Uri, RayVideoFiles.Title, Profiles.ID, Profiles.NickName\n" . "FROM RayVideoFiles\n" . "INNER JOIN Profiles\n" . "ON RayVideoFiles.Owner=Profiles.ID\n" . "ORDER BY Profiles.ID LIMIT 0, 30 "; while($row = mysql_fetch_array($sql)) { echo '<!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" /><style type="text/css">'; echo '.centering {display: block; margin-left: auto; margin-right: auto; margin-top:10px; }'; echo '</style></head><body>'; echo '<div style="margin-left:auto; margin-right:auto; width:170px; background-color:#fff; padding:10px;"><div class="boxContent"><div class="dbContent"> <a href="m/videos/view/'.$row[Uri].'"><img src="'.$dir.''.$row[ID].'.jpg" width="140px" height="110px" style="border:6px double #545565;"/></div></a><br /><p><div class="sys_file_search_title" style="margin-top:-15px;"><a href="m/videos/view/'.$row[Uri].'">'.$row[Title].'</a><br /></div><div class="sys_file_search_from" style="margin-top:0px;">From <a href="'.$row[NickName].'">'.$row[NickName].'</a><br /></div><div class="sys_file_search_when" style="margin-top:0px;">'.$row[Views].' Views</p></div></div></div>'; } I thank you in advance for any help that you can give me on this matter. Hello all, i'm attempting to implement i18n into my project. so I read some tutorials, copied some code and eventually made the following: Code: [Select] /** * applyMultiLingual uses the gettext module from PHP to support multilingual * @param Array $settings */ private static function applyMultiLingual($settings){ /* init global config */ bindtextdomain(self::$project_name,Config::path('i18n')); bind_textdomain_codeset(self::$project_name, 'UTF-8'); textdomain(self::$project_name); if(!array_key_exists('enabled', $settings) || $settings['enabled'] == false){ //initiate default (english) putenv("LC_MESSAGES=en_EN"); setlocale(LC_MESSAGES,'en_EN'); } else{ if(Session::language() === null){ //initiate custom if($settings['default'] == 'auto'){ locale::acceptFromHttp($header); } else{ putenv("LC_MESSAGES=".$settings['default']);setlocale(LC_MESSAGES,$settings['default']); } } else{ putenv("LC_MESSAGES=".Session::language()); setlocale(LC_MESSAGES,Session::language()); } } } The code is (imo) pretty readable, so it sets the textdomain to "project1", and the current language to en_EN. if should search for the translations in DOC_ROOT/i18n/ now, it returns the text between the _(); functions, but I get no translation files in said directory, and I also have no clue how to accomplish this. so what I want to accomplish is this: enable use of function _(), which saves all translations in a folder i18n, and subfolder LOCALE_CODE (ex. DOC_ROOT/i18n/en_EN/messages.po). what am I doing wrong, and how can I fix it? thanks to any who can help, and if more info is needed, ask and you shall receive. Hello Guys.
I am having a trouble viewing a specific column content both in phpMyAdmin and console.It only shows a partial info about the contents inside that column.
I have attached a screenshot of this to give you a demonstration inside that link:
http://i59.tinypic.com/2n6ymqf.jpg
as you can see , the user picked hamburger ,steak and ground beef (and some more), but it seems that it stops showing it right in the middle of the word. Is there any limit for characters in this case?
What would be possible to figure that out please?
Thanks in advance..
Edited by osherdo, 17 December 2014 - 09:11 PM. Hello everybody.
I'm changing some php in one wordpress website.
What I'm trying to do is to pass some values from one website page to the other.
When I do it this way, everything works fine:
Example 1:
First php file: (the one sending the value)
$Variable1 ='Hello'; $_SESSION['kamail']=$Variable1; printf('<li> Variable value:'. $Variable1 .'</li>'); Second php file: (the one getting the value) $Variable2=($_SESSION['kamail']);In the previous "Example 1" I get the correct value in $Variable2 and the print_f also prints the correct value In the next "Example 2", it does print the correct value, but in the second file, $Variable2 gets a completely different value. Example 2: First php file: (the one sending the value) $Variable1 =($javo_directory_query->get('email')); $_SESSION['kamail']=$Variable1; printf('<li> Variable value:'. $Variable1 .'</li>'); Second php file: (the one getting the value) $Variable2=($_SESSION['kamail']);I guess that this haves something to do with pointers or something similar, but I'm a completely PHP beginner, so I'm stuck with this Francisco I'm trying to get an element out of an xml file but it keeps returning just 0 and I'm not sure why...
<g eid="2015010301" gsis="56492" d="Sat" t="8:15" q="F"/>I'm trying to read the ['g eid'] and print it. So I'm using this: $gdate = (int)$xml->gms['g eid']; $arr1 = str_split($gdate); print_r($gdate);I'm using that to see what prints out so I can use it how I need to use it... when I do it returns this: Array ( [0] => 0 ) I'm trying to get it to return the g eid element. What am I doing wrong here? Thanks!!! HEy Guys Here is a snippet of an array: SimpleXMLElement Object ( [report1] => SimpleXMLElement Object ( [ReportHost] => Array ( => SimpleXMLElement Object ( [HostName] => 192.168.2.34 [startTime] => Thu Dec 17 13:58:49 2009 [stopTime] => Thu Dec 17 15:13:13 2009 [netbios_name] => (unknown) [mac_addr] => (unknown) [dns_name] => (unknown) [os_name] => (unknown) [num_ports] => 2 [num_lo] => 0 [num_med] => 0 [num_hi] => 0 [ReportItem] => Array which is printed using print_r($a) now how can i access [HostName] => 192.168.2.34 in the $a array?? Thanks in advance echo '<td>' . $xmlLineItem -> detail.description . '</td>'; I'm trying to do the above. It won't work because of the . in "detail.description". what do I do? |