f



simpleXML and PHP. How to find if a node is empty or exists?

I think that simpleXML is the best thing i've seen in PHP5. It's so
simple (d'ho!) and easy to use when

it comes to reading a simple XML file. The only thing i'm not sure how
to achieve is finding if an XML

node is empty or if the node exist or doesn't exist.

I'm searching the web, but got nothing yet. I was thinking of posting
it here.

This is a condensed version of the code:

<?xml version="1.0" encoding="UTF-8"?>
<CD>
    <title>Shine</title>
    <year>1985</year>
    <label></label>
    <description>Good CD from the 1980s</description>

    <item>
       <track id="18">Moonlight</track>
       <track>Shine</track>
       <track>Absolute</track>
    </item>

    <item>
       <track>Relative</track>
       <track>Star</track>
       <track>Crazy</track>
    </item>
</CD>



$file = 'db_cd_number.xml';
$xml = @simplexml_load_file($file);



//??????
if(title node is empty || title node doesn't exist) {
     echo 'title is empty or doesnt exist, do something';
} else {
     echo 'title OK, continue';
}



//i.e. 2 What about attributes??????????
foreach ($xml->item-> as $item) {
   foreach($item->track as $track) {
      if($track['id'] doesn't exist or empty) {
         echo 'dont show the lyrics';
      }
   }
}


How do i find if a node is empty or if it exists?


Thanks
Marco
0
5/27/2008 10:19:51 PM
comp.lang.php 32646 articles. 0 followers. Post Follow

3 Replies
883 Views

Similar Articles

[PageSpeed] 12

> How do i find if a node is empty or if it exists?

http://www.emopanda.com/tmp/simplexml.php
http://www.emopanda.com/tmp/simplexml_php.txt

I made some changes- I inverted your if-tests so that they're testing
for positives not negatives (it's more intuitive to write, you can use
your !'s if you really need 'em that way for some reason.)
(drawing from string not file for simplicity)

<?php

$string = '<?xml version="1.0" encoding="UTF-8"?>
<CD>
    <title>Shine</title>
    <year>1985</year>
    <label></label>
    <description>Good CD from the 1980s</description>

    <item>
       <track id="18">Moonlight</track>
       <track>Shine</track>
       <track>Absolute</track>
    </item>

    <item>
       <track id="">Relative</track>
       <track id="4">Star</track>
       <track id="0">Crazy</track>
    </item>
</CD>';

$xml = @simplexml_load_string($string);

if( $xml->title && ($xml->title != '') ) {
     echo 'title OK, continue<br/><br/>';
} else {
     echo 'title is empty or doesnt exist, do something<br/><br/>';
}

foreach ($xml->item as $item) {
   foreach($item->track as $track) {
      $attribs = $track->attributes(); //You have to

      if( $attribs['id'] && $attribs['id'] == true) {
      	echo '<b>Lyrics:</b> <i>"Oh baby ' . $track . '- yeah, my honey
baby ' . $track . '~"</i><br/>';
      } else{
        echo 'LYRICS FOR "' . strtoupper($track) . '" WILL NOT NOT
SHOWN<br/>';
      }
   }

}
?>
This should work as long as your ID's are greater than 0.  <title>
works even if the title is the number 0 or the string 'false'.

The .txt file I linked to above has comments with alternate
approaches.

-Derik
0
ReGenesis0 (28)
5/28/2008 1:15:49 AM
On May 27, 9:15 pm, Derik <ReGenes...@aol.com> wrote:
> > How do i find if a node is empty or if it exists?
>
> http://www.emopanda.com/tmp/simplexml.phphttp://www.emopanda.com/tmp/simplexml_php.txt
>
> I made some changes- I inverted your if-tests so that they're testing
> for positives not negatives (it's more intuitive to write, you can use
> your !'s if you really need 'em that way for some reason.)
> (drawing from string not file for simplicity)
>
> <?php
>
> $string = '<?xml version="1.0" encoding="UTF-8"?>
> <CD>
>     <title>Shine</title>
>     <year>1985</year>
>     <label></label>
>     <description>Good CD from the 1980s</description>
>
>     <item>
>        <track id="18">Moonlight</track>
>        <track>Shine</track>
>        <track>Absolute</track>
>     </item>
>
>     <item>
>        <track id="">Relative</track>
>        <track id="4">Star</track>
>        <track id="0">Crazy</track>
>     </item>
> </CD>';
>
> $xml = @simplexml_load_string($string);
>
> if( $xml->title && ($xml->title != '') ) {
>      echo 'title OK, continue<br/><br/>';} else {
>
>      echo 'title is empty or doesnt exist, do something<br/><br/>';
>
> }
>
> foreach ($xml->item as $item) {
>    foreach($item->track as $track) {
>       $attribs = $track->attributes(); //You have to
>
>       if( $attribs['id'] && $attribs['id'] == true) {
>         echo '<b>Lyrics:</b> <i>"Oh baby ' . $track . '- yeah, my honey
> baby ' . $track . '~"</i><br/>';
>       } else{
>         echo 'LYRICS FOR "' . strtoupper($track) . '" WILL NOT NOT
> SHOWN<br/>';
>       }
>    }
>
> }
>
> ?>
> This should work as long as your ID's are greater than 0.  <title>
> works even if the title is the number 0 or the string 'false'.
>
> The .txt file I linked to above has comments with alternate
> approaches.
>
> -Derik

Just one question: Why do you use this twice : if( $attribs['id'] &&
$attribs['id'] == true). Is this a typo or it should be called twice?

Thanks
0
5/28/2008 3:51:18 AM
On May 27, 9:15 pm, Derik <ReGenes...@aol.com> wrote:
> > How do i find if a node is empty or if it exists?
>
> http://www.emopanda.com/tmp/simplexml.phphttp://www.emopanda.com/tmp/simplexml_php.txt
>
> I made some changes- I inverted your if-tests so that they're testing
> for positives not negatives (it's more intuitive to write, you can use
> your !'s if you really need 'em that way for some reason.)
> (drawing from string not file for simplicity)
>
> <?php
>
> $string = '<?xml version="1.0" encoding="UTF-8"?>
> <CD>
>     <title>Shine</title>
>     <year>1985</year>
>     <label></label>
>     <description>Good CD from the 1980s</description>
>
>     <item>
>        <track id="18">Moonlight</track>
>        <track>Shine</track>
>        <track>Absolute</track>
>     </item>
>
>     <item>
>        <track id="">Relative</track>
>        <track id="4">Star</track>
>        <track id="0">Crazy</track>
>     </item>
> </CD>';
>
> $xml = @simplexml_load_string($string);
>
> if( $xml->title && ($xml->title != '') ) {
>      echo 'title OK, continue<br/><br/>';} else {
>
>      echo 'title is empty or doesnt exist, do something<br/><br/>';
>
> }
>
> foreach ($xml->item as $item) {
>    foreach($item->track as $track) {
>       $attribs = $track->attributes(); //You have to
>
>       if( $attribs['id'] && $attribs['id'] == true) {
>         echo '<b>Lyrics:</b> <i>"Oh baby ' . $track . '- yeah, my honey
> baby ' . $track . '~"</i><br/>';
>       } else{
>         echo 'LYRICS FOR "' . strtoupper($track) . '" WILL NOT NOT
> SHOWN<br/>';
>       }
>    }
>
> }
>
> ?>
> This should work as long as your ID's are greater than 0.  <title>
> works even if the title is the number 0 or the string 'false'.
>
> The .txt file I linked to above has comments with alternate
> approaches.
>
> -Derik

Hey thanks Derik.
This is what i've been looking for.

Thanks again
Marco
0
5/28/2008 3:55:38 AM
Reply:

Similar Artilces:

PHP Training Institute In Delhi, Live Projects on PHP. Short Term PHP Courses, PHP Scripts, PHP Training with Live Projects.
Vserve Global offers short term PHP: Hypertext Preprocessor Training Course, which is a widely used, general-purpose scripting language that was originally designed for web development, to produce dynamic web pages. It can be embedded into HTML and generally runs on a web server, which needs to be configured to process PHP code and create web page content from it. It can be deployed on most web servers and on almost every operating system and platform free of charge.PHP is installed on over 20 million websites and 1 million web servers. TOPICS:- >> Core PHP Language >> HTML, Cascad...

PHP within PHP...
I took over the support of a website that is set up something like this inside one of the pages: include_once("header.php"); <?php //to get the content of the page they do this: $content = mysql_query("select content etc...); echo $content; ?> include_once("footer.php"); I am having problems evaluating any php that is used in the mysql content. Is there a way to get the mysql withing the mysql to run? Thank you for your time, Mandragon On Sep 17, 12:56 pm, Mandrago...@gmail.com wrote: > I took over the support of a website that is set up something like > this inside one of the pages: > > include_once("header.php"); > > <?php > //to get the content of the page they do this: > $content = mysql_query("select content etc...); > > echo $content; > ?> > > include_once("footer.php"); > > I am having problems evaluating any php that is used in the mysql > content. Is there a way to get the mysql withing the mysql to run? > > Thank you for your time, > > Mandragon Sorry, The question should read: "Is there a way to get the php withing the echo $htmlcontent to run?" Of course you are, $content is a resource. The MySQL Query resource. try this: $content = mysql_query('bla bla bla'); while ($row = mysql_fetch_assoc($content)) { $result[] = $row; } $content = $result; Now you can use $content ;). In answer to your edit... eval($co...

php to php obj
Hi All, Is there any tool to convert the .php files into its object files in deploying the files to other's server like java classes are deployed? Thanks in advance --AR John7481 <arjohn7481@hotmail.com> wrote or quoted: > Is there any tool to convert the .php files into its object files in > deploying the files to other's server like java classes are deployed? To what end? Do you want a PHP obfuscator? They tend not to be needed - since the code remains on the server. Do you want a PHP squeezer? Again - since PHP remains on the server that is of reduced importance. PHP obfuscators and squeezers are out there - but what exactly are you looking for? -- __________ |im |yler http://timtyler.org/ tim@tt1lock.org Remove lock to reply. With total disregard for any kind of safety measures Tim Tyler <tim@tt1lock.org> leapt forth and uttered: > John7481 <arjohn7481@hotmail.com> wrote or quoted: > >> Is there any tool to convert the .php files into its object >> files in deploying the files to other's server like java >> classes are deployed? > > To what end? > > Do you want a PHP obfuscator? They tend not to be needed - > since the code remains on the server. > > Do you want a PHP squeezer? Again - since PHP remains on the > server that is of reduced importance. > > PHP obfuscators and squeezers are out there - but what exactly > are you looking for? I think he'...

php outside php (?)
Sounds weird, i know. What i want/wonder is the following: PHP can do the next: <?php if($foo == 'bar') { ?> Ow yeah, foo is bar! <?php }; ?> But how can i do the following: <?php $foo= ?> this is what foo looks like. <?php }; ?> This way i could edit the content of $foo in DW's design-view. I hope it's clear enough for you all to understand... Greetings frizzle. frizzle wrote: > But how can i do the following: > > <?php > > $foo= > > ?> > this is what foo looks like. > <?php > > }; > > ?> > > This way i could edit the content of $foo in DW's design-view. > I hope it's clear enough for you all to understand... <?php ob_start(); ?> this is what foo looks like. <?php $foo=ob_get_clean(); ?> -- Justin Koivisto - justin@koivi.com http://koivi.com Wow, little late on the reply, but i still wanted to thank you for your help. This is exactly what i meant, and it works great! :D Thanks again. ...

Best PHP Training | PHP Development Training | PHP Training Institute
Tops Technologies provides php and mysql certification courses in ahmedabad, baroda, surat, Rajkot, Udaipur, Gujarat, india.PHP Training with MySQL is an introductory course in the PHP and MySQL technology. Mysql and php training course, php for beginners, sql training courses, PHP Training courses, php courses, mysql training courses, php mysql course. For More Details :- http://www.tops-int.com ...

PHP with Indian PHP Developers
Dear all, If you want to make a PHP web application, or need to <a href="http:// www.virtueinfo.com/php-developers/hire-php-programmers-developers-india.htm">Hire PHP Developer</a>contact a leading <a href="http://www.virtueinfo.com/ php-developers/php-web-development.htm"> PHP Web Development Compnay</ a> <a href="http://www.virtueinfo.com/php-developers/php-web-programming- php-developers-india.htm">Offshore PHP web development India</a> On Thu, 25 Feb 2010 01:37:02 -0800 (PST), Virtue Info wrote: > Dear all, > > > If you want to make a PHP web application, or need to <a href="http:// > www.example.com/php-developers/hire-php-programmers-developers-india.htm">Hire > PHP Developer</a>contact a leading <a href="http://www.example.com/ > php-developers/php-web-development.htm"> PHP Web Development Compnay</ > a> > > ><a href="http://www.example.com/php-developers/php-web-programming- > php-developers-india.htm">Offshore PHP web development India</a> > Third time's the charm? Not exactly a ringing endorsement of the skills you've got available or your testing method reliablity... -- 12. One of my advisors will be an average five-year-old child. Any flaws in my plan that he is able to spot will be corrected before implementation. --Peter Anspach's list of things to do as an ...

PHP does not parse .PHP files
I have this problem with PHP that someone might be able to help. With CLI, I am able to execute my .php files. For example, if I type "php phpinfo.php" , this works fine on my system. If I put the phpinfo.php file is in /var/www/html and I try to access it through the browser, I get the content of the file and not the execution of the file. Instead of display the info of PHP, I got the text of the file as: <?php phpinfo(); ?> Why? Thanks Phong Ho wrote: >I have this problem with PHP that someone might be able to help. > >With CLI, I am able to execute my ....

about php lang
plz told me that what is the php lang., how does it works and where it used. mani <msb.jod@gmail.com> wrote: > plz told me that what is the php lang., how does it works and where it > used. There is a good explanation at http://lmgtfy.com/?q=php regards Henrik -- The address in the header is only to prevent spam. My real address is: hc3(at)poolhem.se Examples of addresses which go to spammers: root@localhost postmaster@localhost On 16 Jun 2009, mani <msb.jod@gmail.com> wrote: > plz told me that what is the php lang., how does it works and > where it used. Lulz. <http://www.google.com/> -- ~Curtis Anonymous (1984 IOCCC winner): int i;main(){for(;i["]<i;++i){--i;}"];read('-'-'-',i+++"hell\ o, world!\n",'/'/'/'));}read(j,i,p){write(j/p+p,i---j,i/i);} mani schreef: > plz told me that what is the php lang., how does it works and where it > used. http://en.wikipedia.org/wiki/Php Tip: If you want to learn something about a subject totally new to you, try wikipedia for a reasonable intro. Regards, Erwin Moller -- "There are two ways of constructing a software design: One way is to make it so simple that there are obviously no deficiencies, and the other way is to make it so complicated that there are no obvious deficiencies. The first method is far more difficult." -- C.A.R. Hoare ...

Does PHP need the .php extension ?
Hi guys, When I use PHP I give my file the .php extension. I always wondered if it could be an .htm page with a <script> block that the PHP resides in, the same way you would do JavaScript. If you can do it that way are there any benifits to that method ? Take care, Cyrus "Cyrus D." <satan@invalid.org> writes: > Hi guys, > > When I use PHP I give my file the .php extension. I always wondered if it > could be an .htm page with a <script> block that the PHP resides in, the > same way you would do JavaScript. If you can do it that way are the...

Php constants in php.ini
I am trying to set user_agent = PHP_VERSION in php.ini. In my php.ini the instructions say that you can use constants in the php.ini file. The only constants I can get to work, though, are the error level constants like E_ALL, E_ERROR, E_WARNING, etc., ... Is anyone aware of some sort of trick to getting others to work? (I was thinking it would be nice to have the user agent string used by my Php scripts to use PHP_VERSION in the string.) -- ***************************** Chuck Anderson • Boulder, CO http://www.CycleTourist.com Integrity is obvious. The lack of it is common. *****...

Send array from php to php
HI every one I' try to send array from web page to php file but no data are show I'm using session to store data and this is my code //////////////////////////////////////////////////////////////////////// $data = $cart_items; session_register('data'); foreach ($cart_items as $cart_item) { echo "<tr>"; echo " <td><span class='style2'>".$cart_item->name."</span></td>"; echo " <td><span class='style2'>".$cart_item->description."</ span></td>"; echo " <td><span class='style2'>".$cart_item->price." S.R.</span></ td>"; echo " <td><span class='style2'>".$cart_item->quantity."</span></ td>"; echo " <td><span class='style2'>".$cart_item->price * $cart_item- >quantity."</span></td>"; echo " <td><span class='style4'><a href='order.php?action=del&id=". $cart_item->object_id."'>[del]</a></span></td>"; echo "</tr>"; \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ \ and this is my php code to get the data //////////////////////////////////////////////////////// <?php foreach ($data as $item) { echo "<tr>"; print " &l...

php://memory and php://temp
http://php.net/manual/en/wrappers.php.php per the documentation: php://memory and php://temp are both listed under "Allows Appending" what am I missing / what's the point? They only seem to work with read/write modes such as fopen('php://memory','rw'); closing the handle, or trying to open another handle without closing the first essentially erase the contents... so what's the point of fopen('php://memory','a') ? you'll a) be appending nothing, b) no way to read what you just wrote? sure would be nice if you could $fh = fopen('php://memory', 'w'); fwrite($fh, 'test string'); fclose($fh); $fh = fopen('php://memory', 'r'); $result = fgets($fh,2048); fclose($fh); echo $result; On 10/12/2010 9:44 PM, BKDotCom wrote: > http://php.net/manual/en/wrappers.php.php > per the documentation: php://memory and php://temp are both listed > under "Allows Appending" > > what am I missing / what's the point? > > They only seem to work with read/write modes such as > fopen('php://memory','rw'); > > closing the handle, or trying to open another handle without closing > the first essentially erase the contents... so what's the point of > fopen('php://memory','a') ? > you'll > a) be appending nothing, > b) no way to read what you just wrote? > > sure would be nice if you could > > $fh = ...

php notification through php sdk
Hi there I want to build a e-commerce website similar to wish.com and I have chosen opencast as my framework of choice. Now wish has a feature that when you save a product in wish and if you are logged in with Facebook or gmail all of your friends will get a notification that your friends has saved a item on wish. I want a similar feature on my site Now I know Facebook provide a sdk JavaScript and php and wish might be using something similar but I am using open cart can I open home page or product page in the sdk Thanks On 3/20/2015 7:30 AM, apoorv.kanungo@gmail.com wrote: &g...

why does $_SERVER['PHP_SELF'] say /test.php/test.php for test.php?
I have a PHP script at 127.0.0.1/test.php. It's contents are as follows: <?php echo $_SERVER['PHP_SELF']; ?> And it's output isn't test.php, as I'd expect, or /test.php, but rather, /test.php/test.php. Why? And how do I fix it? El 06/10/2010 6:53, yawnmoth escribi�/wrote: > I have a PHP script at 127.0.0.1/test.php. It's contents are as > follows: > > <?php > echo $_SERVER['PHP_SELF']; > ?> > > And it's output isn't test.php, as I'd expect, or /test.php, but > rather, /test.php/test.php. Why? And how do I fix it? What output do you get if you change it to this? <?php echo '[' . $_SERVER['PHP_SELF'] . ']'; ?> What do your other $_SERVER values look like? <?php print_r($_SERVER); ?> -- -- http://alvaro.es - �lvaro G. Vicario - Burgos, Spain -- Mi sitio sobre programaci�n web: http://borrame.com -- Mi web de humor satinado: http://www.demogracia.com -- On 06/10/10 09:30, "�lvaro G. Vicario" wrote: > El 06/10/2010 6:53, yawnmoth escribi�/wrote: >> I have a PHP script at 127.0.0.1/test.php. It's contents are as >> follows: >> >> <?php >> echo $_SERVER['PHP_SELF']; >> ?> >> >> And it's output isn't test.php, as I'd expect, or /test.php, but >> rather, /test.php/test.php. Why? And how do I fix it? > > What output do you get if you change it ...

php
hi all iv extracted a phptimesheet on my system but the webserver is not able to show the documents in html format...i mean..the <?php headers are also visible on the page... can any one help me out with this. linuxadmin wrote: > hi all > > iv extracted a phptimesheet on my system but the webserver is not able > to show the documents in html format...i mean..the <?php headers are > also visible on the page... > > can any one help me out with this. It sounds like a configuration error with your webserver---it would seem that it's not interpreting PHP files...

PHP
Hi I bought the PHP templates last winter and was trying to experiment with these web templates. I need the adaob 4.53 for PHP as indicatedf in the PHP manuals. The official site does not have it any more. Does anyone this zip file please ? If so, contact me at spiterijesmond@yahoo.co.uk If you use latest versions, the examples in the tutorials will not work as they should. Thanks Jesmond Jesmond: Some minutes ago I sent the file to your email Francisco jesmond.spiteri@visitmalta.com ha escrito: > Hi > I bought the PHP templates last winter and was trying to experiment > with these web templates. I need the adaob 4.53 for PHP as indicatedf > in the PHP manuals. > The official site does not have it any more. > Does anyone this zip file please ? If so, contact me at > spiterijesmond@yahoo.co.uk > If you use latest versions, the examples in the tutorials will not work > as they should. > > Thanks > Jesmond ...

php
Hi Guys, Installed FreeBSD 5.1;fine Got Apache2, MySQL working. Installed php 4.3.4 ok Try to run phpMyAdmin (latest version), but somehow there isn't anything generated. Am I overlooking something? Like installing a lib? Any nfo is welcome Henk Lutgerink http://avatar.demon.nl henk lutgerink wrote: > Hi Guys, > > Installed FreeBSD 5.1;fine Got Apache2, MySQL working. > Installed php 4.3.4 ok > Try to run phpMyAdmin (latest version), but somehow there isn't anything > generated. > Am I overlooking something? > Like installing a lib? You don't say whether you've installed the phpMyAdmin port. (In /usr/ports/databases.) -- Bob London, UK echo Mail fefsensmrrjyaheeoceoq\! | tr "jefroq\!" "@obe.uk" Robert Downes wrote: > henk lutgerink wrote: >> Hi Guys, >> >> Installed FreeBSD 5.1;fine Got Apache2, MySQL working. >> Installed php 4.3.4 ok >> Try to run phpMyAdmin (latest version), but somehow there isn't anything >> generated. >> Am I overlooking something? >> Like installing a lib? > > You don't say whether you've installed the phpMyAdmin port. (In > /usr/ports/databases.) yes, I did install phpMyAdmin in /usr/ports/database. I got the feeling I still have to ./configure, make, make install? If so Please let me know. ps: server is running on http://avatar.demon.nl henk lutgerink wrote:...

US-CA: Los Angeles-Web Developer - PHP Developer - PHP Programmer - PHP
************************************************************** JobCircle.com is the largest regional job board in the Mid-Atlantic region, with tens of thousands of job offerings in PA, NJ, DE, MD, NY, and Washington D.C. To learn more, visit http://www.jobcircle.com?source=ng ************************************************************** Job Title: Web Developer - PHP Developer - PHP Programmer - PHP - MySQL Job Location: CA: Los Angeles Pay Rate: competitive Job Length: full time Start Date: 2011-05-06 Company Name: Cybercoders Contact: Shea Stone Phone: email only Fax: email only Description: Web Developer - PHP Developer - PHP Programmer - PHP - MySQL Web Developer - PHP Developer - PHP Programmer - PHP - MySQL - Javascript - HTML - CSS - Facebook - Skills Required - PHP, PHP4, PHP5, MySQL, Javascript, XHTML, DHTML, HTML5, HTML 5, Flash, actionscript, Facebook, Promotional, Marketing, PHP Developer, PHP Programmer, Web Developer Web Developer - PHP Developer - PHP Programmer - PHP - MySQL - Javascript - HTML - CSS - Facebook API If you are a PHP Programmer or Web Developer with strong skills in PHP Development, please read on! We are an award winning Interactive Agency with offices throughout the world. Were currently looking to add a PHP Developer, with skills in both Front End and Back End development, to our team in Venice, CA. In this role youll be developing Promotional / Marketing web ...

Parsing a php include (which also contains php code)
Hello, I am using the <?php include() ?> statement on my website for organizational purposes. However, one of my includes contains some PHP code. Is there any way for the server to actually parse the include? I've tried this before, and it did not parse the include. Rather, it included the file as just plain ASCII. ======================= /*EXAMPLE 1*/ /*index.php*/ .... <?php include('global/includes/footer.inc') ?> .... /*footer.inc*/ .... <p>&copy 1993-<?php echo date("Y") ?> Kingswood School. All rights reserved.</p> .... /*EXA...

How to find non-existing nodes or nodes with no text.
Ok, this must be simple but the more i search the more i don't find. It's about SimpleXML and PHP. How to find non-existing nodes or nodes with no text My XML file looks a little bit like this: i.e. 1 <discography> <CD> <title></title> <year>1978</year> </CD> </discography> i.e. 2: <discography> <CD> <year>1978</year> </CD> </discography> In i.e. 1, the tag <title> is empty. How do i test for empty tags in PHP? In i.e. 2, the tag <title> doesn't even exist. How do i test for non- existing tags? This is how i get the values from XML in PHP without validation .... //set the XML file name as a PHP string $cd_xml = "db/discography/cd.xml"; //load the XML file $xml = @simplexml_load_file($cd_xml) or die ("Error: The XML file can't open.") ; .... //no validation if empty, creates empty <h1> tags. Not good! <h1><?php echo $xml->CD->title; ?></h1> <h2><?php echo $xml->CD->year; ?></h2> How to validate? Any suggestions? Thanks in advance Marco SM wrote: > Ok, this must be simple but the more i search the more i don't find. > It's about SimpleXML and PHP. > How to find non-existing nodes or nodes with no text > > My XML file looks a little bit like this: > > i.e. 1 > <discography> > <CD> > <title></title>...

How to find non-existing nodes or nodes with no text
Ok, this must be simple but the more i search the more i don't find. It's about SimpleXML and PHP. How to find non-existing nodes or nodes with no text My XML file looks a little bit like this: i.e. 1 <discography> <CD> <title></title> <year>1978</year> </CD> </discography> i.e. 2: <discography> <CD> <year>1978</year> </CD> </discography> In i.e. 1, the tag <title> is empty. How do i test for empty tags in PHP? In i.e. 2, the tag <title> doesn't even exist. How do i test for non- existing tags? This is how i get the values from XML in PHP without validation .... //set the XML file name as a PHP string $cd_xml = "db/discography/cd.xml"; //load the XML file $xml = @simplexml_load_file($cd_xml) or die ("Error: The XML file can't open.") ; .... //no validation if empty, creates empty <h1> tags. Not good! <h1><?php echo $xml->CD->title; ?></h1> <h2><?php echo $xml->CD->year; ?></h2> How to validate? Any suggestions? Thanks in advance Marco <?php if (isset($xml->CD->title) && trim($xml->CD->title) != '') { ?> <h1><?php echo $xml->CD->title ?></h1> <?php } ?> On May 9, 7:01 pm, SM <servandomont...@gmail.com> wrote: > Ok, this must be simple but the more i search the more i don't find. >...

[Fwd: Re: [PHP] PHP and COPY]
This is a multi-part message in MIME format. --------------070801090005010101060104 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Forwarding my question over to here, got no answer on the pgsql-php list. Hope someone can help. --------------070801090005010101060104 Content-Type: message/rfc822; name="Re: [PHP] PHP and COPY" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="Re: [PHP] PHP and COPY" Return-Path: <pgsql-php-owner+M2240@postgresql.org> Received: from www.postgresql.com ...

PHP with Indian PHP Developers #2
Dear all, If you want to make a PHP web application, or need to Hire PHP Developer contact a leading PHP Web Development Compnay http://www.virtueinfo.com/ php-developers/php-web-development.htm ...

where is php.ini for the PHP CLI binary?
#!/bin/php <?php echo "hello, world!"; ?> That produces the following: PHP Warning: Directive 'register_globals' is deprecated in PHP 5.3 and greater in Unknown on line 0 PHP Warning: Directive 'register_long_arrays' is deprecated in PHP 5.3 and greater in Unknown on line 0 hello, world! I'd like to update my php.ini file to make those errors go away but don't know where it is. Any ideas as to how I could go about finding it? yawnmoth wrote: > #!/bin/php > <?php > echo "hello, world!"; > ?> > > That produces the following: > > PHP Warning: Directive 'register_globals' is deprecated in PHP 5.3 > and greater in Unknown on line 0 > PHP Warning: Directive 'register_long_arrays' is deprecated in PHP > 5.3 and greater in Unknown on line 0 > hello, world! > > I'd like to update my php.ini file to make those errors go away but > don't know where it is. Any ideas as to how I could go about finding > it? It is/should be in the root directory where your index.php document is stored. Check with your ISP to confirm that the file is named php.ini. Mine, for example, is named php5.ini, and everything failed miserably before I properly named it. Do you have #!bin/php in the [pagename].php document? Try removing it. Bill B yawnmoth wrote: > #!/bin/php > <?php > echo "hello, world!"; > ?> > > That produces the fol...

Web resources about - simpleXML and PHP. How to find if a node is empty or exists? - comp.lang.php

joestump/python-simplexml · GitHub
A simplistic take on SimpleXML for Python. Contribute to python-simplexml development by creating an account on GitHub.

PHP 使用 SimpleXML Key 遇到 $ 如何取值
(adsbygoogle=window.adsbygoogle - - []).push({});PHP 使用 SimpleXML 抓取後, 通常會對此物件裏面的東西做 for / foreach, 但是當 Key 遇到 $ 開頭, 要如何取此值呢?ex

PHP探针 wdcp
PHP探针 wdcp wdlinux官方论坛 一键安装包 wdcp wdOS wddns wdcdn 免费智能DNS解析 免费CDN加速 探针下载 Server Parameters Server Domain/IP www - www.cnledjoy.cn(127.0.0.1) ...

PHP探针 wdcp
PHP探针 wdcp wdlinux官方论坛 一键安装包 wdcp wdOS wddns wdcdn 免费智能DNS解析 免费CDN加速 探针下载 Server Parameters Server Domain/IP www - aygfgfgf.jvxbyz.cn(43.248.170.175) ...

PHP探针 wdcp
PHP探针 wdcp wdlinux官方论坛 一键安装包 wdcp wdOS wddns wdcdn 免费智能DNS解析 免费CDN加速 探针下载 Server Parameters Server Domain/IP www - bbvng.jvxbyz.cn(43.248.170.175) ...

PHP探针 wdcp
PHP探针 wdcp wdlinux官方论坛 一键安装包 wdcp wdOS wddns wdcdn 免费智能DNS解析 免费CDN加速 探针下载 Server Parameters Server Domain/IP www - sjght.jvxbyz.cn(43.248.170.175) ...

PHP探针 wdcp
PHP探针 wdcp wdlinux官方论坛 一键安装包 wdcp wdOS wddns wdcdn 免费智能DNS解析 免费CDN加速 探针下载 Server Parameters Server Domain/IP www - trttrt.jvxbyz.cn(43.248.170.175) ...

How to upgrade to PHP 5.5 or version 5.4 on Mac OSX 10.9 Mavericks and OSX 10.8
How to download and upgrade PHP version 5.4 or 5.5 on Mac OSX 10.9 and OSX 10.8 including a number of extensions such as mcrypt with this packaged ...

Posters say some women lie about sexual assault - Edmonton
Notice (8) : curl_setopt() [http://php.net/function.curl-setopt]: CURLOPT_SSL_VERIFYHOST with value 1 is deprecated and will be removed as of ...

Page 2 - Reviewed: Zend Studio 3.5 - Add Ons - Microsoft DevSource
Page 2 Reviewed: Zend Studio 3.5 Add Ons Microsoft DevSource:

Resources last updated: 3/23/2016 6:14:50 PM