The Little Guy Posted February 6, 2007 Share Posted February 6, 2007 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? Quote Link to comment Share on other sites More sharing options...
effigy Posted February 7, 2007 Share Posted February 7, 2007 Can you post the code you're parsing and the expected result? You may need to use preg_replace_callback. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 7, 2007 Author Share Posted February 7, 2007 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. Quote Link to comment Share on other sites More sharing options...
effigy Posted February 7, 2007 Share Posted February 7, 2007 <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> Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 7, 2007 Author Share Posted February 7, 2007 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'])); ?> Quote Link to comment Share on other sites More sharing options...
effigy Posted February 7, 2007 Share Posted February 7, 2007 eval requires valid code. Quote Link to comment Share on other sites More sharing options...
The Little Guy Posted February 7, 2007 Author Share Posted February 7, 2007 alright, thanks that works! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.