Reputation: 157
Suppose I have following string :
$str = "PHP code may be embedded into HTML or HTML5 markup, or it can be used in combination with various web template systems, web content management systems and web frameworks.";
Here, I'm printing the substring starting from the word 'combination', and ending upto 'content'
echo substr($str, strpos($str, 'combination'), strpos($str, 'content'));
It is printing from 'combination' and to the end, instead of upto 'content'. Is there anything wrong in the third parameter ?
Upvotes: 0
Views: 172
Reputation: 26153
The third argument for substr should be a string length but not the end position
$i = strpos($str, 'combination');
echo substr($str, $i, strpos($str, 'content') - $i);
Upvotes: 5