PDA

View Full Version : Separating data in title tag to display separately


Daniellez
04-23-2010, 08:53 PM
<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0">
<channel>
<title>Billboard Christian Songs Chart</title>
<link>http://www.billboard.com/</link>
<description />
<item>
<title>1: All Of Creation, MercyMe</title>
<link>http://www.billboard.com/charts/christian-songs</link>
<description>All Of Creation by MercyMe ranks #1</description>
<category>Christian Songs</category>
<pubDate>Sat, 01 May 2010 04:00:00 GMT</pubDate>
<guid isPermaLink="false">2010-05-01 00:00:00.0-10549440</guid>
</item>

</channel>
</rss>


Is it possible (perhaps using php) to separate the 1: from the example above and display it in a separate div? This chart displays the top 25.

Here's how it's currently being called ...

echo "<div>";
echo htmlentities($item['title']);
echo "</div>";

Dormilich
04-24-2010, 01:09 AM
you could get the "1:" out of $item['title'] by any appropriate string operation (e.g. substr()).

Daniellez
04-26-2010, 06:29 PM
you could get the "1:" out of $item['title'] by any appropriate string operation (e.g. substr()).

Is it possible to get an example? Thanks for the reply!

Dormilich
04-26-2010, 08:46 PM
taken from the manual
<?php
echo substr('abcdef', 1); // bcdef
echo substr('abcdef', 1, 3); // bcd
echo substr('abcdef', 0, 4); // abcd
echo substr('abcdef', 0, 8); // abcdef
echo substr('abcdef', -1, 1); // f

// Accessing single characters in a string
// can also be achieved using "square brackets"
$string = 'abcdef';
echo $string[0]; // a
echo $string[3]; // d
echo $string[strlen($string)-1]; // f
?>

Daniellez
04-28-2010, 04:31 PM
I sorta understand this. Because all the numbers in my example above ... 1 through 25 ... have a semicolon after them, can substr look for the first semicolon, grab it AND the numbers (1-25) before it and subsequently display them in the preceding div? Ideally, it would be nice to remove the semicolon altogether but that's not a necessity...




echo "<div>The number would be moved to this div.</div>";

echo "<div>";
echo htmlentities($item['title']);
echo "</div>";

Dormilich
04-28-2010, 09:00 PM
strpos($yourString, ";") will give you the position number of the first semi-colon.