Jump to content

help with php (str & replace code)


houssam_ballout

Recommended Posts

 

 

Hello,

I need help with this,

I need a code that removes double occurrences of \\ only, but not if followed \n. for example

Hello\\n  should display Hello\ + new line

Hello\\\n  should display Hello + new line

Hello\\  should display Hello

Hello\\x  should display Hellox

 

Link to comment
https://forums.phpfreaks.com/topic/251499-help-with-php-str-replace-code/
Share on other sites

does this help?

 

<?php
$text = "Hello\\n Hello\\\n Hello\\  Hello\\x ";
$new_text = str_replace(array("\n","\\n")," <br />",$text);
$new_text = stripslashes($new_text);
//$new_text = str_replace("<br />","\n",$new_text);//reason to be \n ?
echo "$new_text";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.