Page 1 of 1

more PHP help

Posted: Tue Mar 21, 2006 11:16 pm
by dmmh
http://bb.cinemasiafreaks.com/view/?tid=15#97

I have a part in the admin panel where I can set UBB tags if you will for smilies.
I simply comma seperate the different tags and put the smilie name and the tags as one long string into the DB, which takes one row as you might expect

in my forums etc the string needs to be exploded to determine the possible pseudonyms/ tags for a smilie in the DB (line 6+7)

for those images I have to create replacements to run through preg_replace(), which works fine (line 20)
however, the patterns also need to be dynamically generated, which is what kind of fails.
I need to escape certain characters in the pseudonyms, which I where I fail

basically it fails on smilies like: : ) and ; ) because of the ')', which needs to be escaped like '/:\)/'
this should happen on line 15
can someone tell me how I can insert a '\' before a ')' ????

should I just explode it, insert it and the put it back together?

Posted: Tue Mar 21, 2006 11:57 pm
by Zimbo
The advice that I have for you is to just let it flow

Posted: Wed Mar 22, 2006 12:52 am
by 4days
give each smiley its own row in a table, or parse your smilies from a hard-coded array.

Posted: Wed Mar 22, 2006 1:16 am
by glossy
you mean:

$smilies = str_replace(")","\\)",$smilies); ??

Posted: Wed Mar 22, 2006 6:05 am
by dmmh
4days wrote:give each smiley its own row in a table, or parse your smilies from a hard-coded array.
you didnt read properly ;)

Posted: Wed Mar 22, 2006 6:09 am
by dmmh
glossy wrote:you mean:

$smilies = str_replace(")","\\)",$smilies); ??
mmm, feared I had to resort to reg_exp, which is my worst nightmare :D

Posted: Wed Mar 22, 2006 9:32 am
by dmmh
glossy? http://bb.cinemasiafreaks.com/view/?tid=15#93

Warning: preg_replace(): No ending delimiter '/' found in preg_replace_smilies.php on line 33

Warning: preg_replace(): Compilation failed: missing terminating ] for character class at offset 3 in preg_replace_smilies.php on line 33

Posted: Wed Mar 22, 2006 12:35 pm
by ^misantropia^
$patterns[37] is '/:[/' but should be '/:\[/', so escape braces (they're used for character classing, e.g. [0-9a-fA-F] to match a hexadecimal character).

Posted: Wed Mar 22, 2006 3:59 pm
by dmmh
thx, now I still have one error:

Warning: preg_replace(): No ending delimiter '/' found in preg_replace_smilies.php on line 34

Posted: Wed Mar 22, 2006 4:01 pm
by dmmh
btw, it is stripping out slashes where it shouldnt

$this_pseudo = str_replace('[',"\\[",$this_pseudo);
$this_pseudo = str_replace(')',"\\)",$this_pseudo);
$this_pseudo = str_replace('\'',"\\'",$this_pseudo);
$this_pseudo = str_replace('/',"\\/",$this_pseudo);
$this_pseudo = str_replace('(',"\\(",$this_pseudo);

thats how it actually is listed :S

Posted: Wed Mar 22, 2006 11:38 pm
by ^misantropia^

Code: Select all

$this_pseudo = str_replace('\', '\\', $this_pseudo);
$this_pseudo = str_replace('[', '\[', $this_pseudo);
$this_pseudo = str_replace(')', '\)', $this_pseudo);
$this_pseudo = str_replace('/', '\/', $this_pseudo);
$this_pseudo = str_replace('(', '\(', $this_pseudo);
Shouldn't this do the trick? (Note the escaping of the backslash) BTW, the single quote doesn't need escaping since it is not used in regexes.

Posted: Thu Mar 23, 2006 6:52 am
by dmmh
the string replacements are fine, but there is another error now it fails on