473,386 Members | 1,602 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

rss escape

One thing I admire about php is that there is usually a function that
does exactly what you want.

I'm building an RSS feed (something I had in perl).

There's a lot about escaping rss data I don't really understand, I've
been doing this:

'&','&'
'\n','<br \/>'
'’',"'"
'<','&lt;'
'>','&gt;'
'™',''

Is there something in php that can more directly or simply help me
build rss?

Jeff
Sep 21 '08 #1
5 3503
..oO(Jeff)
One thing I admire about php is that there is usually a function that
does exactly what you want.

I'm building an RSS feed (something I had in perl).

There's a lot about escaping rss data I don't really understand, I've
been doing this:

'&','&amp;'
'\n','<br \/>'
'’',"'"
'<','&lt;'
'>','&gt;'
'â„¢',''
For &, < and you can use htmlspecialchars(), for \n use nl2br() if
necessary. The rest shouldn't matter.
Is there something in php that can more directly or simply help me
build rss?
I build my feeds with the DOM extension.

Micha
Sep 21 '08 #2
Michael Fesser wrote:
.oO(Jeff)
> One thing I admire about php is that there is usually a function that
does exactly what you want.

I'm building an RSS feed (something I had in perl).

There's a lot about escaping rss data I don't really understand, I've
been doing this:

'&','&amp;'
'\n','<br \/>'
'’',"'"
'<','&lt;'
'>','&gt;'
'â„¢',''

For &, < and you can use htmlspecialchars(), for \n use nl2br() if
necessary. The rest shouldn't matter.
As always, thanks!
>
> Is there something in php that can more directly or simply help me
build rss?

I build my feeds with the DOM extension.
I've just looked through this. Are you using that to generate the RSS or
to read the html. Care to share any details? I can't see how this would
write an RSS feed, but I may have missed something.

Jeff
>
Micha
Sep 23 '08 #3
..oO(Jeff)
>Michael Fesser wrote:
>I build my feeds with the DOM extension.

I've just looked through this. Are you using that to generate the RSS or
to read the html. Care to share any details? I can't see how this would
write an RSS feed, but I may have missed something.
I use it to create the RSS. My feed is just another script, which
collects the data for the feed and then uses DOM to create the XML for
the feed.

Somewhere in my RSS component I have the following method (slightly
modified here, because the actual data may come from different sources
like a database for example):

private function createXml() {
$doc = new DOMDocument('1.0', 'UTF-8');
$doc->formatOutput = TRUE;
$rss = $doc->createElement('rss');
$rss->appendChild(new DOMAttr('version', '2.0'));
$doc->appendChild($rss);
$channel = $doc->createElement('channel');
$rss->appendChild($channel);
// create channel info like title, description and URL
foreach (getChannelInfoFromSomewhere() as $field =$value) {
$channel->appendChild(new DOMElement($field,
htmlspecialchars($value))
);
}
// create items and append to channel
foreach (getItemDataFromSomewhere() as $data) {
$item = $doc->createElement('item');
foreach ($data as $field =$value) {
$item->appendChild(new DOMElement($field,
htmlspecialchars($value))
);
}
$channel->appendChild($item);
}
return $doc;
}

This method creates the entire feed and returns it as a DOM document.
The calling method then more or less just has to output the XML to the
browser (besides setting correct HTTP response headers):

$xml = $this->createXml()->saveXML();
...
print $xml;

One result of this all you can see here:

http://ra-pauli.de/beratung/verkehrsrecht/rss

Have a look at the source code - this is what is created by my
createXml() method and the DOM::saveXML() output method.

Micha
Sep 23 '08 #4
Michael Fesser wrote:
.oO(Jeff)
>Michael Fesser wrote:
>>I build my feeds with the DOM extension.
I've just looked through this. Are you using that to generate the RSS or
to read the html. Care to share any details? I can't see how this would
write an RSS feed, but I may have missed something.

I use it to create the RSS. My feed is just another script, which
collects the data for the feed and then uses DOM to create the XML for
the feed.

Somewhere in my RSS component I have the following method (slightly
modified here, because the actual data may come from different sources
like a database for example):
Thanks Micha, I hadn't found that yet.

Generally I've been assembling html using templates. But there is a
certain beauty in this method and I'm sure you never have to worry about
whether your XML is well formed (like missing ending tags). I'll work my
way through this later.
>
private function createXml() {
$doc = new DOMDocument('1.0', 'UTF-8');
$doc->formatOutput = TRUE;
$rss = $doc->createElement('rss');
$rss->appendChild(new DOMAttr('version', '2.0'));
$doc->appendChild($rss);
$channel = $doc->createElement('channel');
$rss->appendChild($channel);
// create channel info like title, description and URL
foreach (getChannelInfoFromSomewhere() as $field =$value) {
$channel->appendChild(new DOMElement($field,
htmlspecialchars($value))
);
}
// create items and append to channel
foreach (getItemDataFromSomewhere() as $data) {
$item = $doc->createElement('item');
foreach ($data as $field =$value) {
$item->appendChild(new DOMElement($field,
htmlspecialchars($value))
);
}
$channel->appendChild($item);
}
return $doc;
}

This method creates the entire feed and returns it as a DOM document.
The calling method then more or less just has to output the XML to the
browser (besides setting correct HTTP response headers):

$xml = $this->createXml()->saveXML();
...
print $xml;

One result of this all you can see here:

http://ra-pauli.de/beratung/verkehrsrecht/rss

Have a look at the source code - this is what is created by my
createXml() method and the DOM::saveXML() output method.
Hmm, not at all what I expected! I'll be thinking about this for a
while, but not this morning...

Regards,
Jeff
>
Micha
Sep 24 '08 #5
..oO(Jeff)
>Michael Fesser wrote:
>.oO(Jeff)
>>Michael Fesser wrote:

I build my feeds with the DOM extension.
I've just looked through this. Are you using that to generate the RSS or
to read the html. Care to share any details? I can't see how this would
write an RSS feed, but I may have missed something.

I use it to create the RSS. My feed is just another script, which
collects the data for the feed and then uses DOM to create the XML for
the feed.

Somewhere in my RSS component I have the following method (slightly
modified here, because the actual data may come from different sources
like a database for example):

Thanks Micha, I hadn't found that yet.
You're welcome.
Generally I've been assembling html using templates.
Me too, but only for "normal" pages, not for RSS or the like.
>But there is a
certain beauty in this method and I'm sure you never have to worry about
whether your XML is well formed (like missing ending tags).
Exactly. With DOM I just create the structure of objects, which can then
easily be exported into well-formed markup.

Micha
Sep 24 '08 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Leif B. Kristensen | last post by:
I'm working with a Python program to insert / update textual data into a PostgreSQL database. The text has single and double quotes in it, and I wonder: What is the easiest way to escape quotes in...
3
by: Paul | last post by:
I have an Access 2000 database with a form that is giving me some major headaches. When you open the form, it displays all records and allows editing, but has AllowAdditions set to False so that...
7
by: teachtiro | last post by:
Hi, 'C' says \ is the escape character to be used when characters are to be interpreted in an uncommon sense, e.g. \t usage in printf(), but for printing % through printf(), i have read that %%...
18
by: Steve Litvack | last post by:
Hello, I have built an XMLDocument object instance and I get the following string when I examine the InnerXml property: <?xml version=\"1.0\"?><ROOT><UserData UserID=\"2282\"><Tag1...
4
by: Guadala Harry | last post by:
I need to place the following into a string... How can I properly escape the % " / < and > characters? <table width="100%" border="0" cellspacing="0" cellpadding="4px" class="hfAll"></Table> ...
3
by: Guadala Harry | last post by:
I'd like to know the answer to the following question so I can know what to expect with regard to other similar uses of escape characters and strings. While everything works fine - I'd like to know...
16
by: sudhir | last post by:
hi how to check escape key is pressed when accepting the string as input. Because I do not want to receive a string if user presses the ESCAPE key.. I used ascii code for comparision but I...
15
by: pkaeowic | last post by:
I am having a problem with the "escape" character \e. This code is in my Windows form KeyPress event. The compiler gives me "unrecognized escape sequence" even though this is documented in MSDN....
131
by: Lawrence D'Oliveiro | last post by:
The "escape" function in the "cgi" module escapes characters with special meanings in HTML. The ones that need escaping are '<', '&' and '"'. However, cgi.escape only escapes the quote character if...
5
by: vlsidesign | last post by:
The printf function returns "warning: unknown escape sequence: \040" for a backslash-space combination. If the ascii decimal number for space is 32 and the backslash is 92, why this particular...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.