Preg_Replace and a function HELP
03-02-2010, 09:13 PM
|
Preg_Replace and a function HELP
|
Posts: 10
Name: Travis Bales
|
i have got this preg replace that always returns the value with 1
\\1 doesnt seem to work.
the function is Get_Username2($id);
help please
PHP Code:
$out1 = preg_replace("/\[user\](.*)\[\/user\]/Usi", "".Get_Username2('\\1')."", $out1);
Last edited by JeremyMiller; 03-09-2010 at 04:57 AM..
Reason: Removed un-intended link
|
|
|
|
03-02-2010, 09:38 PM
|
Re: Preg_Replace and a function HELP
|
Posts: 2,815
Name: Matt
Location: Irvine, CA
|
I'm not sure what you are trying to do. You are calling Get_Username2 with the parameter '\\1' and appending it to two empty strings (which has no effect by the way). What does get_username do? what do you expect this expression to do?
You should take a closer look at the preg_replace documentation: http://us2.php.net/manual/en/function.preg-replace.php
Last edited by NullPointer; 03-03-2010 at 08:54 PM..
|
|
|
|
03-03-2010, 06:18 AM
|
Re: Preg_Replace and a function HELP
|
Posts: 10
Name: Travis Bales
|
here is the entire code for the page.
PHP Code:
<? $conn = mysql_connect("localhost","auto","password"); $db = mysql_select_db("tableA"); function Get_Username2($id){ $result = mysql_query("SELECT * FROM `grpgusers` WHERE `id` = '".$id."'"); $worked = mysql_fetch_array($result); $bbuser = New User($worked['id']); $secondsago = time() - $bbuser->lastactive; if($secondsago<=900){ return "<table width='55%' background='http://i48.tinypic.com/15zp0tc.gif'><tr><td width='40%'>".$bbuser->formattedname."</td><td width='15%'>".$bbuser->level."</td><td width='10%'>".$bbuser->cityname."</td></tr><tr><td><center> <a href=spy.php?id=".$worked['id'].">Spy</a></center></td><td> <a href=mug.php?id=".$worked['id'].">Mug</a></td><td width='33%'> <a href=attack.php?id=".$worked['id'].">Attack</a></td></tr></table>"; } if($secondsago>=900){ return "<table width='55%' background='http://i48.tinypic.com/2i12rmx.gif'><tr><td width='40%'>".$bbuser->formattedname."</td><td width='15%'>".$bbuser->level."</td><td width='10%'>".$bbuser->cityname."</td></tr><tr><td><center> <a href=spy.php?id=".$worked['id'].">Spy</a></center></td><td> <a href=mug.php?id=".$worked['id'].">Mug</a></td><td width='33%'> <a href=attack.php?id=".$worked['id'].">Attack</a></td></tr></table>"; } } function callback1($buffer1){ $out1 = $buffer1; $ea_tr = array(":angry:",":mad:",":grin:",":cry:",":raspberry:",":tongue:",":happy:",":dead:",":smile:",":sad:",":shock:",":wink:",":blush:",":zombie:",":haha:",":evil:",":heh:",":shout:",":cool:",":love:",":whip:","mafia-mandemz","andemz","mafiadeath","mafiacrime","mafiamofo","mafiahoodz","mafia3000","mafiahitman","trentonmade","mobsterdeath"); $ea_sr = array ( '[img]smilies/angry.gif[/img]', '[img]smilies/angry-sad.gif[/img]', '[img]smilies/biggrin.gif[/img]', '[img]smilies/cry.gif[/img]', '[img]smilies/rasberry.gif[/img]', '[img]smilies/tongue.gif[/img]', '[img]smilies/super-happy.gif[/img]', '[img]smilies/dead.gif[/img]', '[img]smilies/smile.gif[/img]', '[img]smilies/sad.gif[/img]', '[img]smilies/shock.gif[/img]', '[img]smilies/wink.gif[/img]', '[img]smilies/embarassed.gif[/img]', '[img]smilies/zombie.gif[/img]', '[img]smilies/haha.gif[/img]', '[img]smilies/evil.gif[/img]', '[img]smilies/heh.gif[/img]', '[img]smilies/shout.gif[/img]', '[img]smilies/sleazy-wink.gif[/img]', '[img]smilies/heart.gif[/img]', '[img]smilies/whip.gif[/img]', 'Game-Advertising-is-Banned', 'Game-Advertising-is-Banned', 'Game-Advertising-is-Banned', 'Game-Advertising-is-Banned', 'Game-Advertising-is-Banned', 'Game-Advertising-is-Banned', 'Game-Advertising-is-Banned', 'Game-Advertising-is-Banned', 'Game-Advertising-is-Banned', 'Game-Advertising-is-Banned', ); $out1 = str_replace($ea_tr, $ea_sr, $out1); $out1 = str_replace("[center]", "<center>", $out1); $out1 = str_replace("[/center]", "</center>", $out1); $out1 = str_replace("[u]", "<u>", $out1); $out1 = str_replace("[/u]", "</u>", $out1); $out1 = str_replace("[s]", "<s>", $out1); $out1 = str_replace("[/s]", "</s>", $out1); $out1 = str_replace("[big]", "<font size=5>", $out1); $out1 = str_replace("[/big]", "</font>", $out1); $out1 = str_replace("[img]", "<img src=", $out1); $out1 = str_replace("[admin]", "".Get_Username(1)."", $out1); $out1 = str_replace("[/img]", "></img>", $out1); $out1 = str_replace("[IMG]", "<img src=", $out1); $out1 = str_replace("[/IMG]", "></img>", $out1); $out1 = str_replace("[b]", "<b>", $out1); $out1 = str_replace("[/b]", "</b>", $out1); $out1 = str_replace("[i]", "<i>", $out1); $out1 = str_replace("[/i]", "</i>", $out1); $out1 = preg_replace("/\[url\=(.*)\](.*)\[\/url\]/", "<a href=\"$1\">$2</a>", $out1); $out1 = str_replace("[enter]", "<br>", $out1); $out1 = str_replace("/r/n", "<br>", $out1); $out1 = str_replace("[/color]", "</font>", $out1); $out1 = preg_replace("/\[color=(\#[0-9A-F]{6}|[a-z]+)\]/", '<font color="$1">', $out1); $out1 = preg_replace("/\[user\](.*)\[\/user\]/Usi", "".Get_Username2('$1')."", $out1); $out1 = preg_replace("/\[quote](.*)\[\/quote\]/Uis", "<div></div><div style=\"border:solid 1px;\">\\1</div>", $out1); $out1 = preg_replace("/\[size=(.*)\](.*)\[\/size\]/Usi", "<span style=\"font-size:\\1ex\">\\2</span>", $out1); $out1 = preg_replace("/\[youtube](.*)\[\/youtube\]/Uis", '<object width="560" height="340"><param name="movie" value="http://www.youtube.com/v/$1&hl=en&fs=1&"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/$1&hl=en&fs=1&" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="560" height="340"></embed></object>', $out1); return $out1; } ob_start("callback1"); ?>
|
|
|
|
03-03-2010, 07:11 AM
|
Re: Preg_Replace and a function HELP
|
Posts: 10
Name: Travis Bales
|
the replacement in the preg replace is a function and it will notbackreference properly.
|
|
|
|
03-03-2010, 07:12 AM
|
Re: Preg_Replace and a function HELP
|
Posts: 10
Name: Travis Bales
|
the preg replace does notbackreference properly
|
|
|
|
03-03-2010, 03:38 PM
|
Re: Preg_Replace and a function HELP
|
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
|
Try:
PHP Code:
$out1 = preg_replace("/\[user\](.*)\[\/user\]/esi", "Get_Username2('\\1')", $out1);
__________________
<mgraphic /> - I don't have a solution but I admire the problem.
|
|
|
|
03-03-2010, 04:05 PM
|
Re: Preg_Replace and a function HELP
|
Posts: 10
Name: Travis Bales
|
well, i got no error message, just page errors and no result.
|
|
|
|
03-07-2010, 09:06 PM
|
Re: Preg_Replace and a function HELP
|
Posts: 10
Name: Travis Bales
|
please can someone explain why this isnt working or how to fix this. this is important to me.
|
|
|
|
03-07-2010, 09:17 PM
|
Re: Preg_Replace and a function HELP
|
Posts: 10
Name: Travis Bales
|
the
PHP Code:
"".Get_Username2('\\1')."",
is what wont work.
PHP Code:
$out1 = preg_replace("/\[user\](.*)\[\/user\]/Usi", "".Get_Username2('\\1')."", $out1);
|
|
|
|
03-08-2010, 11:51 AM
|
Re: Preg_Replace and a function HELP
|
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
|
You have to pass the "e" modifier flag in order to evaluate the replace function, and the function must be written as a string (much like you would do using an eval function).
__________________
<mgraphic /> - I don't have a solution but I admire the problem.
|
|
|
|
03-08-2010, 05:08 PM
|
Re: Preg_Replace and a function HELP
|
Posts: 10
Name: Travis Bales
|
um, how might i do that exactly. im new with this preg replace.
|
|
|
|
03-08-2010, 05:17 PM
|
Re: Preg_Replace and a function HELP
|
Posts: 10
Name: Travis Bales
|
never mind i got this thank you alot. 
|
|
|
|
|
« Reply to Preg_Replace and a function HELP
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|