PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
In my script, I have a DB entry that contains htmlspecialchar()d text, both HTML and PHP. I finally got it to be htmlspecialchar so that form elements and whatnot are not parsed AND have a code block like the forums here so that desired code is shown correctly. Problem is, I would like to highlight the area that is inside the [div] tag I have made (hence, showing the code).
If I hightlight_string the entire entry, duh it'll come up wrong. I've been pondering this for a bit and figured someone here can help. Ya'll always do
Last edited by Steveo31 on Thu Dec 02, 2004 1:22 am, edited 1 time in total.
Ok, I tried it and some variations of it now that I understand (sorta) the preg_replace code. Now, on phpfreaks.com, there is a tut that google came back with. It said that the subsections matched in the first part of the code are refered to in the second parameter of the function with an escaped $, then the number slot. So
This makes the div class there, in my case a background color, etc., but the code in the database won't show. It gets parsed. It's stored in a TEXT database, not htmlspecialchar()d.
<?php
$allLines = 'this is a test of the div tagging... [div]<?php $variable = "check this out ma!"; ?>[/div] joy joy joy [div]<?php $variable
=
"check this out ma!"; ?>[/div] some more useless text';
$output = preg_replace('|\[div](.*?)\[/div]|ise','highlight_string("\\1",true)',$allLines);
echo $output;
?>
But one problem- variables in the database are, again, trying to be parsed. I tried escaping but it says theres an "unexpected escape ASCII" or something.
<?php
$allLines = 'this is a test of the div tagging... [div]<?php $variable = "check this out ma!"; ?>[/div] joy joy joy [div]<?php $variable
=
"check this out ma!"; ?>[/div] some more useless text';
$output = preg_replace('|\[div](.*?)\[/div]|ise','highlight_string("\\1",true)',addslashes($allLines));
echo $output;
?>
<table>
<?php
=
Warning: Unexpected character in input: ''' (ASCII=92) state=1 in c:\phpdev\www\projects\multimedia\10 hour\includes\content\articles.php(31) : regexp code on line 7
'Test variable'';
?>
</table>