473,327 Members | 2,055 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,327 software developers and data experts.

Encoding a string?

Suppose I have a string,

e.g. $str = 'good morning';
I want encode the string into a format that doesn't contains any
special character like \n, \r and space etc.
Currently base64_encode is used. But are there any faster methods?
Thanks.

Howa

Feb 19 '06 #1
5 1463
use trim on the string to remove \n \r \t spaces, etc.
$str = 'good morning';
$trimmed = trim($str);

Feb 19 '06 #2
ho******@gmail.com wrote:
I want encode the string into a format that doesn't contains any
special character like \n, \r and space etc.

Currently base64_encode is used. But are there any faster methods?


Try urlencode, addslashes, htmlspecialchars, htmlentities, str_replace,
preg_replace, strtr.

--
E. Dronkert
Feb 19 '06 #3
ho******@gmail.com wrote:
Currently base64_encode is used. But are there any faster methods?


No. These are some functions used to encode 11 MB of data and the time
they took to do so:

base64_encode: 0.105 sec
urlencode: 0.122 sec
addslashes: 0.114 sec
htmlspecialchars: 0.400 sec
htmlentities: 1.145 sec

Feb 19 '06 #4
On 2006-02-19, ho******@gmail.com <ho******@gmail.com> wrote:
Suppose I have a string,

e.g. $str = 'good morning';
I want encode the string into a format that doesn't contains any
special character like \n, \r and space etc.


addslashes

--

Bye.
Jasen
Feb 20 '06 #5
oh....great! seems base64 is the fastest one.

Thanks for your information!

Rdgs,
howa

Feb 20 '06 #6

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

Similar topics

10
by: Christopher H. Laco | last post by:
Long story longer. I need to get web user input into a backend system that a) only grocks single byte encoding, b) expectes the data transer to be 1 bytes = 1 character, and c) uses the HP Roman-6...
2
by: Eric Cadwell | last post by:
We are encoding strings using XMLElement: private string XMLEncode(string val) { if(val.Length == 0) return string.Empty; XmlElement element = xmldoc.CreateElement("E"); element.InnerText =...
8
by: Demon News | last post by:
I'm trying to do a transform (Using XmlTransform class in c#) and in the Transform I'm specifying the the output xsl below: <xsl:output method="xml" encoding="UTF-8" indent="no"/> the...
12
by: Tamir Khason | last post by:
I have Windows Form application recieved data from clipboard and convert its encoding based on some ruls. So doing following: //from source to multiple targets System.Text.Encoding targ1 =...
4
by: fitsch | last post by:
Hi, I am trying to write a generic RSS/Atom/OPML feed client. The problem is, that those xml feeds may have different encodings: - <?xml version="1.0" encoding="ISO-8859-1" ?>... - <?xml...
2
by: lprisr | last post by:
Hi, I have double byte characters in the content that I am returning using Web Services. However, the encoding in the xml file returned by Web Services is utf-8 and I am unable to read the...
4
by: Bob | last post by:
Hi Need to produce a Doc with no encoding info. Is there anyway of doing this? Thanks Bob i.e. <?xml version=\"1.0\" ?>
4
by: Terry Olsen | last post by:
I use the following code to create an XML string: Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim tw As New StringWriter Dim xml...
8
by: Erwin Moller | last post by:
Hi group, I could use a bit of guidance on the following matter. I am starting a new project now and must make some decisions regarding encoding. Environment: PHP4.3, Postgres7.4.3 I must...
0
by: deloford | last post by:
Hi This is going to be a question for anyone who is an expert in C# Text Encoding. My situation is this: I have a Sybase database which is firing back ISO-8559 encoded strings. I am unable to...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.