tags:

views:

39

answers:

2

We have variable with text:

$text = 'I use something similar to pull the most recent post from my blog and display a snapshot of it on my home page.';

How to strip first 40 symbols of this text? (including spaces).

Should work like this:

echo strip_text($text, 40);

Thanks.

A: 

Use PHP's substr:

$stripped = substr($text, 0, 40);
fabrik
He wants to strip the first 40 characters, not output them.
Mark Trapp
The reason you've been downvoted is because your answer is wrong: your answer outputs the first 40 characters of `$text` rather than stripping the first 40 characters.
Mark Trapp
@Mark Trapp: your solution also outputs the text.
Happy
+2  A: 

With substr:

echo substr($text, 40);
Mark Trapp
He wants to strip the first 40 characters, not output them.
fabrik
The reason you've been downvoted is because your answer is wrong: your answer outputs the first 40 characters of $text rather than stripping the first 40 characters.
fabrik
your solution is wrong, it gives 40 letters from the end of the string.
Happy
seems someone doesn't think before upvoting an answer
Happy
No, my solution strips the first 40 characters, and returns the rest of the string, as you had asked for in your question. `substr($text, -40)` would return the last 40 characters of the string, and `substr($text, 0, 40)` would return the first 40 characters.
Mark Trapp