Substr causing problems if it cuts an html tag in half...
Posted: Tue Dec 12, 2006 1:26 pm
I have a bit of code and I only want the first 25 characters to show.. let say....
Will echo the first 25 characters with the html with no problems.
However....
If my first 25 characters are the first part of a peice of html code.... like....
This displays the image but messes up all of the rest of the html on the page until we get to another peice of code that closes the image's title or alt. Is there a safer way to display only the first 25 characters?
Code: Select all
$content = "Hello world <p> with more than 25 characters";
$content = substr("$content", 0, 25);
echo"$content";However....
If my first 25 characters are the first part of a peice of html code.... like....
Code: Select all
$content = "<img src='img.gif' alt='really long alt text' title='really long title text' />";
$content = substr("$content", 0, 25);
echo"$content";