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;
?>
Related
This question already has answers here:
Get text between HTML tags [duplicate]
(3 answers)
Closed 6 years ago.
I need to get the Text value of a HTML a link dynamically stored in PHP variable like
$term = 'Meat';
so the result will be Meat only. can you please let me know how to do this? Thanks
You could strip all tags from the text using strip_tags
echo strip_tags($term);
echoes: Meat
Reference: http://php.net/manual/en/function.strip-tags.php
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:
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:
Php trim string at a particular character
(7 answers)
Closed 8 years ago.
I have a mysql codes which i need to do that trim and leading with PHP, anyone know how to write below logics with PHP code.
LEFT(TRIM(LEADING 'DHL ' FROM CONT_NAAM),20)
TRIM(LEADING 'DHL JVGL' FROM CONT_NAAM)
You can use preg_replace:
substr(preg_replace('/^(DHL )+/', '', $cont_naam), 1, 20)
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']);