note 88457 added to book.simplexml
| From: | oscargodson at gmail dot com | Date: | Sun, 25 Jan 2009 11:05:10 +0000 |
| Subject: | note 88457 added to book.simplexml | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-149748@lists.php.net to get a copy of this message | ||
To add to what others have said, you can't directly put a $_GET or $_POST value into a variable
then into an attribute using SimpleXML. You must first convert it to an integer.
This will NOT work
<?php
$page_id = $_GET['id'];
echo $xml->page[$page_id]
?>
You will get something like:
Notice: Trying to get property of non-object in /Applications/MAMP/htdocs/mysite/index.php on line
10
However, this WILL work and is much simpler then using (string) or other methods.
<?php
$page_id = intval($_GET['id']);
echo $xml->page[$page_id]
?>
----
Server IP: 64.71.164.2
Probable Submitter: 70.58.196.7
----
Manual Page -- http://www.php.net/manual/en/book.simplexml.php
Edit -- https://master.php.net/note/edit/88457
Del: integrated -- https://master.php.net/note/delete/88457/integrated
Del: useless -- https://master.php.net/note/delete/88457/useless
Del: bad code -- https://master.php.net/note/delete/88457/bad+code
Del: spam -- https://master.php.net/note/delete/88457/spam
Del: non-english -- https://master.php.net/note/delete/88457/non-english
Del: in docs -- https://master.php.net/note/delete/88457/in+docs
Del: other reasons-- https://master.php.net/note/delete/88457
Reject -- https://master.php.net/note/reject/88457
Search -- https://master.php.net/manage/user-notes.php