473,738 Members | 4,774 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

trying to make characters safe for my RSS feed

Whenever users write a post in Microsoft Word and then post it to
their weblogs using my PHP software, their RSS feed ends up being
corrupted with garbage characters which violate the well-formedness of
their XML and therefore cause their newsreaders to die.

This function will probably make the character strings completely safe
for XML? I don't care about having garbage characters in the RSS feed,
I just want the RSS feed to show up, without causing anyone's newsfeed
reader to die.
function command($string =false) {
$howMany = strlen($string) ;

$newString = "";
for ($i=0; $i < $howMany; $i++) {
$char = $string[$i];
$asciiNum = ord($char);
if ($asciiNum > 32 && $asciiNum < 128) {
$newString .= $char;
} else {
$newString .= "'";
}
}

return $newString;
}

Oct 10 '05 #1
4 1901
Okay, the function doesn't work:

http://www.whatisliberalism.com/pdsFiles/page2533.xml

All the white space got replaced, but the entity that is kill the feed
is still there.

What is wrong with this function?

function command($string =false) {
$howMany = strlen($string) ;

$newString = "";
for ($i=0; $i < $howMany; $i++) {
$char = $string[$i];
$asciiNum = ord($char);
if ($asciiNum > 32 && $asciiNum < 128) {
$newString .= $char;
} else {
$newString .= "'";
}
}

return $newString;
}

Oct 10 '05 #2
lk******@geocit ies.com wrote:
Okay, the function doesn't work:

http://www.whatisliberalism.com/pdsFiles/page2533.xml

All the white space got replaced, but the entity that is kill the feed
is still there.

What is wrong with this function?

function command($string =false) {
$howMany = strlen($string) ;

$newString = "";
for ($i=0; $i < $howMany; $i++) {
$char = $string[$i];
$asciiNum = ord($char);
if ($asciiNum > 32 && $asciiNum < 128) {
$newString .= $char;
} else {
$newString .= "'";
}
}

return $newString;
}

I don't know what's wrong with its operation, but you're reinventing the
wheel.

Have a look at http://uk2.php.net/manual/en/function.strtr.php

Colin
Oct 13 '05 #3
>>>All the white space got replaced, but the entity that is kill the
feed
is still there.
What is wrong with this function?
function command($string =false) {
$howMany = strlen($string) ;
$newString = "";
for ($i=0; $i < $howMany; $i++) {
$char = $string[$i];
$asciiNum = ord($char);
if ($asciiNum > 32 && $asciiNum < 128) {
$newString .= $char;
} else {
$newString .= "'";
}
}
return $newString;
}

I don't know what's wrong with its operation, but you're
reinventing the
wheel.

Have a look at http://uk2.php.net/manual/en/function.strtr.php


I apologize for my ignorance, but I don't see how that reinvents the
wheel. The function you point to would allow me to replace the
offending character if I knew what it was, but I don't know what it
is.That's why I'm walking through the string one character at a time,
checking its ASCII number. Yet even that isn't working. I can't figure
out why. But that's the question.

Oct 25 '05 #4
All the white space got replaced, but the entity that is kill the
feed
is still there.


&acirc; XML is not HTML.

---
Steve

Oct 25 '05 #5

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

Similar topics

4
1856
by: lkrubner | last post by:
I've a client who, I think, writes his essays in Microsoft Word on a Macintosh, then copies and pastes it to a form to upload it to his weblog. The weblog then creates an RSS feed. The weblog and RSS feed are created using a simple PHP script I wrote. His RSS feed is not validating, apparently because of the Word "smart quotes". This is a guess on my part. I need to find out for sure what character is causing the rss failure. How do I do...
6
2387
by: barthome1 | last post by:
Hello, My company collects data from non-US sources. We are starting projects where this data will be output in an XML document and passed around to our applications and third party tools. The data includes some of the extended characters. We get strange accent marks, italics and the like. These characters have decimal value in the 200+ range.
35
2534
by: Durgesh Sharma | last post by:
I want to use strrchar(source_string,last_char ) function from string.h header file,to find out the last occurrence of the NON SPACE Alphanumeric Character. Then i will put a NULL CHAR after incrementing that position,received by strrchar() function by 1. This is my idea of Trimming a string from right . According to the definition of the strrchar function,i am supposed to
2
3049
by: Buddy Ackerman | last post by:
Apparently .NET strips these white space characters (MSXML doesn't) regardless of what the output method is set to. I'm using <xsl:text> </xsl:text> to output a tab character and <xsl:text> </xsl:text> to output a carriage return and line feed but they get stripped at some point. I'm passing a StringWriter to the XslTransform.Transform method. Anyway to get this to actually output the tab and carriage and line feed characters?
1
7436
by: Programmer | last post by:
I have this following code: x= tempStr.IndexOf((char)13, 0); The string tempSTR = " Heading"
4
4375
by: randy1200 | last post by:
Using Visual Studio 2005. I'm using XmlReader to read data into a string variable in C#. Works great! Every once in a while, I see that the string data contains a symbol that looks like a square. Any suggestions on how to filter out characters that don't appear on a keyboard? I hate to let the end-user see these square characters. --
1
1387
by: Adam W. | last post by:
So I wrote a little video podcast downloading script that checks a list of RSS feeds and downloads any new videos. Every once in a while it find a character that is out of the 128 range in the feed and my script blows up: Traceback (most recent call last): File "C:\Users\Adam\Desktop\Rev3 DL\Rev3.py", line 88, in <module> mainloop() File "C:\Users\Adam\Desktop\Rev3 DL\Rev3.py", line 75, in mainloop update()
14
3612
by: jt | last post by:
hello everyone.., i'm using ubuntu 8.04 OS. I'm not able to output the non-printable ascii chatacters. for eg. printf("%c",1); // nothing is outputted..... is there any way to output these characters...???
13
3921
by: Liang Chen | last post by:
Hope you all had a nice weekend. I have a question that I hope someone can help me out. I want to run a Python program that uses Tkinter for the user interface (GUI). The program allows me to type Chinese characters, but neverthelss is unable to show them up on screen. The follow is some of the error message I received after I logged off the program: "Could not write output: <type "exceptions: UnicodeEncodeError'>, 'ascii' codec can't...
0
8788
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9476
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9335
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9263
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9208
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6751
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4825
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3279
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2193
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.