473,545 Members | 2,688 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Replace in PHP

I'm new to PHP and come from and ASP background...

I want to replace line feeds in user submited textareas with <br> or
<p> or <div>. In ASP I do this to replace carriage return/line feeds
with <p> in a record of a recordset...

Replace(rsWhate ver("fld_whatev er_field"), vbCrLf, "<p>")

I don't know how to accomplish this in PHP. I know I have to use
str_replace() but I'm confused by the syntax.

Thanks for the help!

Jan 26 '06 #1
3 4630
check out the nl2br function which replaces linefeed characters with
linebreak tags or the str_replace function which works like the replace
function in VB.

Joe

"John K" <ki*****@yahoo. com> wrote in message
news:11******** **************@ g43g2000cwa.goo glegroups.com.. .
I'm new to PHP and come from and ASP background...

I want to replace line feeds in user submited textareas with <br> or
<p> or <div>. In ASP I do this to replace carriage return/line feeds
with <p> in a record of a recordset...

Replace(rsWhate ver("fld_whatev er_field"), vbCrLf, "<p>")

I don't know how to accomplish this in PHP. I know I have to use
str_replace() but I'm confused by the syntax.

Thanks for the help!

Jan 26 '06 #2
John K wrote:
I'm new to PHP and come from and ASP background...

I want to replace line feeds in user submited textareas with <br> or
<p> or <div>. In ASP I do this to replace carriage return/line feeds
with <p> in a record of a recordset...

Replace(rsWhate ver("fld_whatev er_field"), vbCrLf, "<p>")
an example from the PHP manuals:

$text="this is my text string\r\n";
$text=str_repla ce("\r\n","<br> ",$text);
or
$text=str_repla ce("\r\n","<br> ",$_POST['myvariable']);
where:
"\r" = CR
"\n" = LF
I don't know how to accomplish this in PHP. I know I have to use
str_replace() but I'm confused by the syntax.
str_replace([old_string],[new_string],[text string])

where old_string and new_string can be an array of text.

Thanks for the help!


You're welcome.

Michael.
Jan 26 '06 #3
Excellent! Works perfectly!!

Jan 26 '06 #4

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

Similar topics

4
3016
by: Craig Keightley | last post by:
Can these lines of sql statements be consolidated into one sql statement (possibly using reg exps??) BEGIN CODE ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Update applications Set news_article = replace(news_article, '<FONT face="Times New Roman" color=#000000 size=3>', ''); Update applications Set news_article...
12
8138
by: Barnes | last post by:
Does anyone know of a good way to use the JavaScript string.replace() method in an ASP form? Here is the scenario: I have a form that cannot accept apostrophes. I want to use the replace() so that the apostrophe is automatically replace with two '' . Reason being--SQL Server does not like apostrophes being sent to database. I've tried to...
6
5651
by: Danny | last post by:
I need an asp command to strip out from a string all extra punctuation such as apostrophe, comma, period, spaces dashes, etc etc and just leave the letters. Can anybody give me some ideas? Thanks
9
9136
by: Peter Row | last post by:
Hi, I know this has been asked before, but reading the threads it is still not entirely clear. Deciding which .Replace( ) to use when. Typically if I create a string in a loop I always use a StringBuilder. At present I am porting a VB6 webclass app to VB.NET and therefore I am trying to make it as efficent as possible via the new...
4
3834
by: Cor | last post by:
Hi Newsgroup, I have given an answer in this newsgroup about a "Replace". There came an answer on that I did not understand, so I have done some tests. I got the idea that someone said, that the split method and the regex.replace method was better than the string.replace method and replace function. I did not believe that.
3
3302
by: Goran Djuranovic | last post by:
Hi all, I ran into a problem where my XMLTextReader fails on .Read() when I have "<" character in one of the attribute's values. What I am trying to do is replace illegal characters ("<", "&" , etc.) with legal stuff ("&lt;", "&amp;", etc.), before I send the XML text to a SQL Server stored procedure. Currently, I am using XMLTextReader and StringWriter...
3
16909
by: TOXiC | last post by:
Hi everyone, First I say that I serched and tryed everything but I cannot figure out how I can do it. I want to open a a file (not necessary a txt) and find and replace a string. I can do it with: import fileinput, string, sys fileQuery = "Text.txt" sourceText = '''SOURCE'''
6
15556
by: JackpipE | last post by:
Here is my replace query and I need to run this on every column in my table. Right now I manually enter the column name (_LANGUAGES_SPOKEN) but this is time consuming and would like to automate this process as much as possible. Update PROFILE SET LANGUAGES_SPOKEN = replace(cast(_LANGUAGES_SPOKEN as nvarchar(255)),char(13)+char(10),':') ...
5
9227
by: V S Rawat | last post by:
I was trying to use back-to-back replace functions to convert a url: str1 = str.replace("%2F","/").replace("%3F","?").replace("%3D","=").replace("%2 6","&"); It didn't replace all 4 types of strings. Then, I googled and found this suggestion of some JavaScript Tutorials, so I used replace with a regex with a global switch:
15
1883
by: =?Utf-8?B?TWlrZSAiWU9fQkVFIiBC?= | last post by:
I have a text file that contains about 8 to 10 text sequences that I need to replace. I want to search and replace all 8 to 10 text sequence anytime I run this script Here is what I have so far. Const ForReading = 1 Const ForWriting = 2
0
7432
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...
0
7943
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...
1
7456
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...
1
5359
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...
0
5076
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3490
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
1
1919
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
1
1044
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
743
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...

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.