php - substr not working correctly? -
i creating forum, , working on bbcode section. bbcode works, implementing emoticon system. syntax looks this: [e]:)[/e]
i made string testing purposes:
[b]hello world[/b] [i]i having fun[/i] [e]:)[/e] how doing today?! <3[color=blue]:d[/color]
and returning not want. here returning:
:)[/e] how doing today?! <3[color=bl
this code:
function bbcode($str) { if (strpos($str, '[e]')!==false && strpos($str, '[/e]')!==false) { $f = strpos($str, '[e]') + 3; $s = strpos($str, '[/e]'); $emote = substr($str, $f, $s); } homecoming $emote; }
note $f , $s returning right positions, 45 , 47, substr not cutting string correctly. why , how can prepare it?
"string substr ( string $string , int $start [, int $length ] )
returns portion of string specified start and length parameters."
$emote = substr($str, $f, $s - $f);
php
No comments:
Post a Comment