Search code examples
phpstringrsslimitfeed

Limit string chars - PHP


I am building an RSS script with mysql, and i dont want an extra field in the database... i want to shrink down the body of the article with a "... Read More" but im not sure how i can limit the number of chars echoed out onto the page?

Of course not this syntax, but something along the lines of:

echo(limit($row['newsBody'], 1000));

I dont mind if it takes 15 lines of code to do this ;)

P.S. I am sure limit() is a function, please dont tell me .. its just an example ;)

Thanks in advance!


Solution

  • echo(substr($row['newsBody'], 0, 1000));
    

    The substr function is what you are looking for. Or you can use mb_substr if you are dealing with multi-byte strings.