0

I have a dynamically generated XML file that is working great except for the RSS generated is written out as & in the

Sample URL: http://tinyurl.com/bbhnpg6

Actual Working URL that http://tinyurl.com/crbuny5

How do I properly escape the $URL variable so that it properly writes the &? Can someone show this sample updated properly please?

// selecting data from "mytable"
// mytable = your article table name
$query = @mysql_query("SELECT * FROM TABLE1 ORDER BY EntryDate ASC LIMIT 0,5");
while($row = @mysql_fetch_array($query)){
// [title] = change it to your article title
$title = $row['MLNumber'];
$link = $row['ListingRid'];
$url = "http://www.domain.com/residential?frame=TAL&MLNO=";
$Unit= $row['Unit'];
$City= $row['City'];
$ZipCode= $row['ZipCode'];
$price = $row['SearchPrice'];
$description = $row['MarketingRemarks'];
$SubdivisionDisplay = $row['SubdivisionDisplay'];

echo '<item>';
echo '<title>' . $Unit . ' ' . $City . ', ' . $ZipCode . ' -' . $SubdivisionDisplay . '</title>';
echo '<link>' . $url . '' . $title . '</link>';
echo '<description><![CDATA[<p><strong>$' . $price . '.00</strong><BR> ' . $description . '<BR> ]]></description>';
//echo '<pubDate>' . date("D, d M Y H:i:s O", time()) . '</pubDate>';
echo '</item>';
}
echo '</channel>';
echo '</rss>';
?>
4
  • dupe stackoverflow.com/questions/3957360/… Commented Nov 18, 2012 at 22:38
  • No it's not...that is a poorly asked question with no clear answer. I've provided an exact sample and links to the problem. Commented Nov 18, 2012 at 22:46
  • In fact it really should be &amp; instead of just &. XML should be encoded like that. I also tried to add your feed to Google Reader and when I click the article link it redirects me to the right link (with & instead of &amp;) Commented Nov 18, 2012 at 23:06
  • Related, more generally applicable question: stackoverflow.com/questions/3957360/… Commented Feb 14, 2013 at 21:25

1 Answer 1

1
$url = str_replace('&','&amp;', $url);
Sign up to request clarification or add additional context in comments.

2 Comments

If I replace the $url with you suggestion I'll lose the actual URL? I'm not sure I understand?
& should be escaped in XMl and encoded with &amp;, who ever is using it will properly read it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.