more PHP help

Open discussion about any topic, as long as you abide by the rules of course!
Post Reply
dmmh
Posts: 2501
Joined: Thu Jan 04, 2001 8:00 am

more PHP help

Post 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?
[i]And shepherds we shall be, for thee my Lord for thee, Power hath descended forth from thy hand, that our feet may swiftly carry out thy command, we shall flow a river forth to thee, and teeming with souls shall it ever be. In nomine patris, et fili, et spiritus sancti.[/i]
Zimbo
Posts: 239
Joined: Fri Feb 11, 2005 10:50 pm

Post by Zimbo »

The advice that I have for you is to just let it flow
Zimbabwe
4days
Posts: 5465
Joined: Tue Apr 16, 2002 7:00 am

Post by 4days »

give each smiley its own row in a table, or parse your smilies from a hard-coded array.
glossy
Posts: 2285
Joined: Tue Apr 30, 2002 7:00 am

Post by glossy »

you mean:

$smilies = str_replace(")","\\)",$smilies); ??
dmmh
Posts: 2501
Joined: Thu Jan 04, 2001 8:00 am

Post 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 ;)
[i]And shepherds we shall be, for thee my Lord for thee, Power hath descended forth from thy hand, that our feet may swiftly carry out thy command, we shall flow a river forth to thee, and teeming with souls shall it ever be. In nomine patris, et fili, et spiritus sancti.[/i]
dmmh
Posts: 2501
Joined: Thu Jan 04, 2001 8:00 am

Post 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
[i]And shepherds we shall be, for thee my Lord for thee, Power hath descended forth from thy hand, that our feet may swiftly carry out thy command, we shall flow a river forth to thee, and teeming with souls shall it ever be. In nomine patris, et fili, et spiritus sancti.[/i]
dmmh
Posts: 2501
Joined: Thu Jan 04, 2001 8:00 am

Post 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
[i]And shepherds we shall be, for thee my Lord for thee, Power hath descended forth from thy hand, that our feet may swiftly carry out thy command, we shall flow a river forth to thee, and teeming with souls shall it ever be. In nomine patris, et fili, et spiritus sancti.[/i]
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Post 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).
dmmh
Posts: 2501
Joined: Thu Jan 04, 2001 8:00 am

Post by dmmh »

thx, now I still have one error:

Warning: preg_replace(): No ending delimiter '/' found in preg_replace_smilies.php on line 34
[i]And shepherds we shall be, for thee my Lord for thee, Power hath descended forth from thy hand, that our feet may swiftly carry out thy command, we shall flow a river forth to thee, and teeming with souls shall it ever be. In nomine patris, et fili, et spiritus sancti.[/i]
dmmh
Posts: 2501
Joined: Thu Jan 04, 2001 8:00 am

Post 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
[i]And shepherds we shall be, for thee my Lord for thee, Power hath descended forth from thy hand, that our feet may swiftly carry out thy command, we shall flow a river forth to thee, and teeming with souls shall it ever be. In nomine patris, et fili, et spiritus sancti.[/i]
^misantropia^
Posts: 4022
Joined: Sat Mar 12, 2005 6:24 pm

Post 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.
dmmh
Posts: 2501
Joined: Thu Jan 04, 2001 8:00 am

Post by dmmh »

the string replacements are fine, but there is another error now it fails on
[i]And shepherds we shall be, for thee my Lord for thee, Power hath descended forth from thy hand, that our feet may swiftly carry out thy command, we shall flow a river forth to thee, and teeming with souls shall it ever be. In nomine patris, et fili, et spiritus sancti.[/i]
Post Reply