faqts : Computers : Programming : Languages : PHP : kms

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

5 of 12 people (42%) answered Yes
Recently 4 of 10 people (40%) answered Yes

Entry

How can I change "[...]some text. And more..." to "<br><br><br>some text. And more..." with ereg_rep

Nov 6th, 2007 13:10
Chris Carter, nick meyer, the Phantom,


couple different ways to go when search/replacing text, depending what 
you want to do with the results.

a simple way to format text to html friendly code, like you might do 
when writing to a file for later includes, is: 

$trans = get_html_translation_table (HTML_ENTITIES);
$for_comments = strtr ($form_comments, $trans);
$comments = str_replace ("\n", "<BR>", "$form_comments");


if you want to use regular expressions or something more complex, try: 

$string = str_replace("href=\"/", "href=\"http://www.uac.pdx.edu/",  
$string);
$string = ereg_replace("<SCRIPT[^>]*>(.*)<\/SCRIPT>", "\n<!-- /SCRIPT 
TRIMMED FROM HERE/ -->\n\n ", $string);


-nm