Ahhh ok, Thanks guys, I get what I have to do. With the link Mordecai gave me and the sample code by Jayant I should be able to figure this out pretty easily (I haven't user these 'regular expressions' before).
Thanks very much guys!
Ahhh ok, Thanks guys, I get what I have to do. With the link Mordecai gave me and the sample code by Jayant I should be able to figure this out pretty easily (I haven't user these 'regular expressions' before).
Thanks very much guys!
$code=eregi_replace("<a href="http://([[" target="blank">)]www.([[])[/url]","<a href=\"http://www.\1\" target=blank>\2</a>",$code);
This has some errors in it. Namely, the quotes are not escaped, which makes it not work. When I tried fixing it to test, I got these errors:
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in d:\apache\htdocs\test.php on line 3
Warning: REG_EPAREN:parentheses not balanced in d:\apache\htdocs\test.php on line 3
Edit: nevermind, I'm slow to post today, already fixed.
Yeah Mordecai he said that vB messed it all up, the code he gave as at attachment was a lot different. Silly vB!
lol, and thanks for your help!
well vB uses the tag of url, img. since img is off. url one got replaced with <a href=...
and it stripped slashes. all double backslashes became single, and escaped quotes became unecaped
Hm... I'm kinda getting it...
I used the sample supplied by Jayant to produce this:
<?php
$string = "[*php]hello[/*php]";
$newstring = ereg_replace( "\\\\[*php\\\\]([^\\\\[]*)\\\\[/*php\\\\]",highlight_string("\\\\1", true),$string );
echo $newstring;
?>
Which works ok I guess, printing 'hello' in the font it uses as if it was php code.
But when I try with a string like:
$string = "[php]<?php echo \"hello\">[/php]";
it prints nothing, why's that?
i will be printing.
right click the webpage and click view source
what is happening is <?... gets printed, and browser confuses it with invalid html
try using:
htmlspecialchars(highlight_string("\1", true))
instead of
highlight_string("\1", true)
Thanks Jayant, but that didn't work.
It seemed to have turned the < font > and < code > tages into text rather than HTML so it could be printed, but left the php code in tact :S
The source this time did have it, but still not correct... any other suggestions?
Thanks for all your help
highlight_string(htmlspecialchars("\1", true))
this should do it
Before you said it i tried that as
highlight_string(htmlspecialchars("\1"), true);
(The one u gave had true as an argument for htmlspecialchars, which didn't work)
Unfortunately, the same problem as at first.... it didn't even try to convert the text, but it was there in the source sure enough.
its almost like highlight_string isn't doing its job properly :S
lol, any more idea?
hmmm, ya misplaced the ).
if you can tell what all you see on screen and what all is in the page source. it will be easier to help
No, highlight string takes a true argument, now htmlspecialchars. Doing it your way handed the 'true' argument to htmlspecialchars, which it doesnt take, and gave no second argument to hightlight_string.
I'll upload a text file with the output from each function.
Edit: In the first case, i got nothing, and in the second i got a \1 followed by the square.
try using two htmlspecialchars()
like
highlight_string(htmlspecialchars(htmlspecialchars("\1")), true);
lol, same thing.... its quite wierd.... I can tell it to highlight_string the string normally... yet when it replaces it it doesn't want to do it...
Hmm... is there anyway I could see how this site does it?
Edit:
Actually, is there anyway I could somehow copy \1 out of there and put it into a string, that I could then highlight later? I tried assigning it ($string3 = "\1"), and got "\1" rather than the text from inside, which makes sense.
Also, what does "\1" mean anyway?
I have YaBB already actually lol, but it's in Perl, and I cant seem to find any of the source files anyway lol :S
I think I'll just leave it for today, come back when I have more experience.
Thanks for all your help Jayant
~ Paul