sjb78
New Member
Posts: 7
|
Post by sjb78 on Oct 1, 2012 18:44:37 GMT -5
Hello,
I was wondering when extracting my code for the cascading style sheet, why does it cut off my last 6 characters?
My code is: function cascade($myString) { $start = strpos($myString, "<style"); $finish = strpos($myString, "style>"); $length = $finish - $start; $final = htmlspecialchars(substr($myString, $start, $length)); echo $final; }
and when it is called, it displays: <style...code code code code.... </
It won't display the last 6 characters and I was wondering if anyone could explain why it does that? And is there a way to fix it?
Thanks!
|
|
adm88
New Member
Posts: 10
|
Post by adm88 on Oct 1, 2012 19:07:50 GMT -5
It's because strpos for "style>" returns position for the first character of the substring you are looking for (style> in your case). You can simply do $length = ($finish + 6) - $start and it should work:)
|
|
sjb78
New Member
Posts: 7
|
Post by sjb78 on Oct 1, 2012 20:48:57 GMT -5
I understand that now! Thank you for your help, I appreciate it!
|
|
pae6
New Member
Posts: 4
|
Post by pae6 on Oct 3, 2012 0:10:06 GMT -5
I didn't even notice this. ::goes back and checks code::
|
|