This question already has answers here:
How to use nl2br() to handle string with '\r\n'?
(4 answers)
Closed 8 years ago.
When I use the function nl2br like result I see /r /n
example:
in a textarea I wrote
Hello,
how are you?,
fine
php
echo nl2br($_POST['message']);
result to screen
\r\nHello,
\r\nhow are you?
\r\nfin
how can I fix it? thank you
try this:
$newmessage = preg_replace('#(\\\r|\\\r\\\n|\\\n)#','<br />', $_POST['message']);
Related
This question already has answers here:
How do I replace certain parts of my string?
(5 answers)
Closed 6 years ago.
i have a problem.
I want in php to replace all 'blablabla' with 'bla'(because i hate blablabla). Here's my code:
<?php
$string = 'Dracula always says BlaBlaBla but says he never says BlaBlaBla';
$result = answer to replace here
?>
Thanks
Use srt_replace function to do that like this :
str_replace("BlaBlaBla","bla",$string);
You can use something like this:
str_replace("BlaBlaBla","bla",$string)
Also you can find it here in the docs: http://php.net/manual/en/function.str-replace.php
This question already has answers here:
Remove new lines from string and replace with one empty space
(21 answers)
Closed 7 years ago.
I have this lines so i need delete blank line:
Fichier TESTTT
testt have that
I've used str_replace('\r\n','',$text); but always I have this line blank
Thanks in advance
try this
preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $string);
This question already has answers here:
How do you parse and process HTML/XML in PHP?
(31 answers)
Closed 7 years ago.
I am working on a small php script I have an html code like this :
<p>text1</p> <p>text2</p> <p>text3</p>
Is it possible to use php to get only the content of the first paragraph which is text1 ?
Yes, is possible:
$text = '<p>text1</p> <p>text2</p> <p>text3</p>';
$text = preg_replace('/<\/p>[ ]{1,}<p>/', '</p><p>', $text);
$splitedText = explode('</p>', $text);
var_dump(substr($splitedText[0],3));
I Hope this helps!
This question already has answers here:
'Why' doesn't the script print anything? [duplicate]
(5 answers)
Closed 9 years ago.
This is a weird issue.
I just trying to print/create a string like below :
sort="name<string>"
so I just do
echo 'sort="name<string>"';
however, it seems that PHP store it as :
sort="name"
What do I miss?
Try this...
echo htmlspecialchars('sort="name<string>"', ENT_QUOTES, 'UTF-8');
Try this:
echo 'sort="name<String>"';
This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to wrap long lines without spaces in HTML?
I have a long text "jkjkllllllllljcsccncnmchdkcjhvcjdkvk".how to wrap this text in php
Use this:
<?php
$iamlong = "woooooooooooord.";
$iamwrapped = wordwrap($iamlong , 8, "<br>", true);
echo $iamwrapped;
?>