Solved

Maybe it would be a foreach echo instead of print_r

Posted on 2013-11-16
2
310 Views
Last Modified: 2013-11-16
<?php // RAY_temp_rgb192.php
error_reporting(E_ALL);
echo '<pre>';

// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28287746.html#a39633174

$url = 'http://www.experts-exchange.com/viewCodeSnippet.jsp?refID=39631349&rtid=20&icsi=3';

// THE XML FILE AT THE GIVEN $url IS UNUSABLE, SO IT'S INSERTED HERE
$xml = <<<EOD
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc>http://website.com/</loc> <priority>1.0</priority> </url> <url> <loc>http://www.website.com/portfolio/</loc> <priority>0.9</priority> </url> <url> <loc>http://www.website.com/about/</loc> <priority>0.9</priority> </url> <url> <loc>http://www.website.com/contact/</loc> <priority>0.9</priority> </url> <url> <loc>http://www.website.com/portfolio/branding/</loc> <priority>0.8</priority> </url> <url> <loc>http://www.website.com/portfolio/web-wordpress/</loc> <priority>0.8</priority> </url> <url> <loc>http://www.website.com/portfolio/social-media/</loc> <priority>0.8</priority> </url> <url> <loc>http://www.website.com/portfolio/print/</loc> <priority>0.8</priority> </url> <url> <loc>http://www.website.com/portfolio/branding/cabrillo-youth-summer-institute.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/santacruz-popup-artparty.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/red-house.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/what-to-do-in.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/room-service.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/new-evolution.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/film-production-studio.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/rogueIBO.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/booster-bath.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/pilar-macchione.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/katie-mcmahon.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/genesis.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/tequila-jacks.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/em-integrated.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/em.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/orignauxmoose.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/corey-gegner.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/trey-hock.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/nathan-jones.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/morgan-victoria.php</loc> </url> </urlset>
EOD;

// MAKE AN OBJECT
$obj = simplexml_load_string($xml);

// USE AN ITERATOR TO RECOVER THE PARTS OF THE URL ARRAY
$urlist = array();
foreach ($obj->url as $u)
{
    $l = (string)$u->loc;
    $p = (string)$u->priority;
    $d = "$l,$p";
    $d = rtrim($d, ',');
    $urlist[] = $d;
}

// SHOSW THE WORK PRODUCT
print_r($urlist);

Open in new window


Can you modify this code to do an echo
Maybe it would be a foreach echo instead of print_r (last line)
0
Comment
Question by:rgb192
2 Comments
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 39653866
Please see http://www.laprbass.com/RAY_temp_rgb192.php

<?php // RAY_temp_rgb192.php
error_reporting(E_ALL);
echo '<pre>';

// SEE http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_28296209.html

$url = 'http://www.experts-exchange.com/viewCodeSnippet.jsp?refID=39631349&rtid=20&icsi=3';

// THE XML FILE AT THE GIVEN $url IS UNUSABLE, SO IT'S INSERTED HERE
$xml = <<<EOD
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc>http://website.com/</loc> <priority>1.0</priority> </url> <url> <loc>http://www.website.com/portfolio/</loc> <priority>0.9</priority> </url> <url> <loc>http://www.website.com/about/</loc> <priority>0.9</priority> </url> <url> <loc>http://www.website.com/contact/</loc> <priority>0.9</priority> </url> <url> <loc>http://www.website.com/portfolio/branding/</loc> <priority>0.8</priority> </url> <url> <loc>http://www.website.com/portfolio/web-wordpress/</loc> <priority>0.8</priority> </url> <url> <loc>http://www.website.com/portfolio/social-media/</loc> <priority>0.8</priority> </url> <url> <loc>http://www.website.com/portfolio/print/</loc> <priority>0.8</priority> </url> <url> <loc>http://www.website.com/portfolio/branding/cabrillo-youth-summer-institute.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/santacruz-popup-artparty.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/red-house.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/what-to-do-in.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/room-service.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/new-evolution.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/film-production-studio.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/rogueIBO.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/booster-bath.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/pilar-macchione.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/katie-mcmahon.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/genesis.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/tequila-jacks.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/em-integrated.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/em.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/orignauxmoose.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/corey-gegner.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/trey-hock.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/nathan-jones.php</loc> </url> <url> <loc>http://www.website.com/portfolio/branding/morgan-victoria.php</loc> </url> </urlset>
EOD;

// MAKE AN OBJECT
$obj = simplexml_load_string($xml);

// USE AN ITERATOR TO RECOVER THE PARTS OF THE URL ARRAY
$urlist = array();
foreach ($obj->url as $u)
{
    $l = (string)$u->loc;
    $p = (string)$u->priority;
    $d = "$l,$p";
    $d = rtrim($d, ',');
    // SHOW THE WORK PRODUCT
    echo PHP_EOL . $d;
}

Open in new window

Best, ~Ray
0
 

Author Closing Comment

by:rgb192
ID: 39653924
one row per line echo works great

thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now