Jump to content

[SOLVED] highlight_string, and bbcode


The Little Guy

Recommended Posts

I have some bbcode, it looks like this:

 

$find = array('/\[page=(.*)\]/i');
$replace = array(');<h3>$1</h3>highlight_string(\''); 

 

highlight_string(preg_replace($find,$replace,$row['code']));

 

It works 95% of the way, what I want is for when it finds [page=xxx] I want the highlight_string function to close, then change [page=xxx] to <h3>xxx</h3>, then open highlight_string again.

 

right now, it does change the [page=xxx] to the correct <h3>xxx</h3>, but it is in the highlight_string function, so instead of printing the heading to the screen, it prints <h3>xxx</h3> as code, and I don't want that.

 

how can I fix this?

 

Link to comment
Share on other sites

Code In the database:

[page=image.php]
<?php
header("Content-type: image/png");
$string = "abcdefghijklmnopqrstuvwxyz0123456789";
for($i=0;$i<6;$i++){
$pos = rand(0,36);
$str .= $string{$pos};
}

$img_handle = ImageCreate (60, 15) or die ("Cannot Create image");
//Image size (x,y)
$back_color = ImageColorAllocate($img_handle, 121, 143, 138);
//Background color RBG
$txt_color = ImageColorAllocate($img_handle, 0, 0, 0);
//Text Color RBG
ImageString($img_handle, 31, 5, 0, $number, $txt_color);
Imagepng($img_handle);

session_start();
$_SESSION['img_number'] = $str;
?>

[page=form.php]
<form action="result.php">
<img alt="Random Number" src="image.php"> 
<input type="text" name="num"><br>
<input type="submit" name="submit" value="Check">
</form>

[page=result.php]
<?php
if($_SESSION['img_number'] != $_POST['num']){
echo'The number you entered doesn\'t match the image.';
}
?>

 

When displayed on the page should look like this:


 

image.php

<?php

header("Content-type: image/png");

$string = "abcdefghijklmnopqrstuvwxyz0123456789";

for($i=0;$i<6;$i++){

$pos = rand(0,36);

$str .= $string{$pos};

}

 

$img_handle = ImageCreate (60, 15) or die ("Cannot Create image");

//Image size (x,y)

$back_color = ImageColorAllocate($img_handle, 121, 143, 138);

//Background color RBG

$txt_color = ImageColorAllocate($img_handle, 0, 0, 0);

//Text Color RBG

ImageString($img_handle, 31, 5, 0, $number, $txt_color);

Imagepng($img_handle);

 

session_start();

$_SESSION['img_number'] = $str;

?>

 

form.php

<form action="result.php">

<img alt="Random Number" src="image.php">

<input type="text" name="num"><br>

<input type="submit" name="submit" value="Check">

</form>

 

result.php

<?php

if($_SESSION['img_number'] != $_POST['num']){

echo'The number you entered doesn\'t match the image.';

}

?>


each [page=xxx] Should turn into header text, not a codded version of codded text.

Link to comment
Share on other sites


<pre>
<?php
// Where the code is for this example.
$code = file_get_contents('source.txt');
// Split the data between 

 and non-

 tags.
$code = preg_split('/(^\[page=.+?\])/m', $code, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY);
foreach ($code as $line) {
	// For page items...
	if (strpos($line, '[page=') === 0) {
		echo preg_replace('/^\[page=(.+?)\]/', '<h3>\1</h3>', $line);
	}
	// For code items...
	else {
		highlight_string($line);
	}
}
?>
</pre>

Link to comment
Share on other sites

I'm trying to use eval(), but Im getting this error:

Parse error: syntax error, unexpected ')' in /home/.marble/ryannaddy/snippets.tzfiles.com/db.php(29) : eval()'d code on line 1

 

<?php
$find = array('/\[page=(.*)\]/i');
$replace = array(eval(");echo'<h3>$1</h3>';highlight_string(")); 

//Search database code is here (this works)

highlight_string(preg_replace($find,$replace,$row['code']));
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.