|
-
Apr 25th, 2002, 04:59 PM
#1
Thread Starter
Stuck in the 80s
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.
Last edited by The Hobo; Apr 26th, 2002 at 10:44 AM.
-
Apr 25th, 2002, 07:36 PM
#2
Fanatic Member
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
-
Apr 26th, 2002, 10:43 AM
#3
Thread Starter
Stuck in the 80s
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.
-
Apr 26th, 2002, 01:11 PM
#4
Addicted Member
Change
Code:
$line = substr($crap, $j +6, $k - 12);
to
Code:
$line = substr($crap, $j +6, $k - $j - 6);
That should fix it.
What is the answer to this question?
-
Apr 26th, 2002, 01:30 PM
#5
Thread Starter
Stuck in the 80s
Beautiful! I think that corrected it. Thanks alot, Martin.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|