-
Looping
I have this code:
PHP Code:
<?php
include('snippets/format.php');
$crap = "Text!\n(code)Private Sub Form_Load()(/code)Text is cool!" . "\n(code)Dim strString As String(/code)";
if (strpos($crap, "(code)") == false) {
echo "no";
} else {
do {
$j = strpos($crap, "(code)");
if ($j == false) {
break;
}
$k = strpos($crap, "(/code)", $j);
$line = substr($crap, $j +6, $k - 12);
$code = $line; //format($line);
$crap = str_replace("(code)" . $line . "(/code)", $code, $crap);
} while ($j != false);
echo $crap;
}
?>
Which searches through $crap to find all the (code) tags and replace what's between them with formatted text, like is done in these posts.
However it just loops indefinetly and never catches more than one (code) tag.
-
This may or may not be your entire problem but you may want to fix this line:
PHP Code:
$j = strpos($crap, "[ code] ");
to
PHP Code:
$j = strpos($crap, "[ code ] ");
-Matt
-
It's not that way in my code, I had to put spaces in there otherwise the forums would put all that within code tags. I'll go through and edit to to make it look better.
Any ideas would be really helpful.
-
Change
Code:
$line = substr($crap, $j +6, $k - 12);
to
Code:
$line = substr($crap, $j +6, $k - $j - 6);
That should fix it.
-
Beautiful! I think that corrected it. Thanks alot, Martin. :)