John Davidson

PHP, WordWrap how to cut only text and don't cut html code

0 comments
Message:


i have a problem.


wordwrap($getPagina[$i]["message"], 60, "<br/>", true)

I have to use the wordwrap function to not go too far with the text in a table. I inserted wordwrap and it worked fine but now that I also have to insert some html code I have a problem. The wordwrap function cuts my html code (for example span cuts it to me in sp and an) and it no longer works.
How can I do to limit the wordwrap function to plain text only avoiding html codes? Thanks



My Answer:
To cut only text and not break words in PHP using the `wordwrap` function, you can set the `cut` parameter to `false`. This will prevent the function from breaking words and only cut the text at the specified width.

Here is an example:

php
$text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.";

$wrapped_text = wordwrap($text, 30, "\n", false);

echo $wrapped_text;


In this example, the `wordwrap` function will wrap the text at 30 characters and will not break words. The `"\n"` parameter is used to insert a newline character after each line.

Rate this post

4 of 5 based on 6206 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us