Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Preg_Replace and a function HELP
Old 03-02-2010, 09:13 PM Preg_Replace and a function HELP
Novice Talker

Posts: 10
Name: Travis Bales
Trades: 0
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
tbales is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-02-2010, 09:38 PM Re: Preg_Replace and a function HELP
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
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
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 03-03-2010 at 08:54 PM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 03-03-2010, 06:18 AM Re: Preg_Replace and a function HELP
Novice Talker

Posts: 10
Name: Travis Bales
Trades: 0
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>&nbsp; <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%'>&nbsp;&nbsp;&nbsp; <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>&nbsp; <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%'>&nbsp;&nbsp;&nbsp; <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");
?>
tbales is offline
Reply With Quote
View Public Profile
 
Old 03-03-2010, 07:11 AM Re: Preg_Replace and a function HELP
Novice Talker

Posts: 10
Name: Travis Bales
Trades: 0
the replacement in the preg replace is a function and it will notbackreference properly.
tbales is offline
Reply With Quote
View Public Profile
 
Old 03-03-2010, 07:12 AM Re: Preg_Replace and a function HELP
Novice Talker

Posts: 10
Name: Travis Bales
Trades: 0
the preg replace does notbackreference properly
tbales is offline
Reply With Quote
View Public Profile
 
Old 03-03-2010, 03:38 PM Re: Preg_Replace and a function HELP
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
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.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 03-03-2010, 04:05 PM Re: Preg_Replace and a function HELP
Novice Talker

Posts: 10
Name: Travis Bales
Trades: 0
well, i got no error message, just page errors and no result.
tbales is offline
Reply With Quote
View Public Profile
 
Old 03-07-2010, 09:06 PM Re: Preg_Replace and a function HELP
Novice Talker

Posts: 10
Name: Travis Bales
Trades: 0
please can someone explain why this isnt working or how to fix this. this is important to me.
tbales is offline
Reply With Quote
View Public Profile
 
Old 03-07-2010, 09:17 PM Re: Preg_Replace and a function HELP
Novice Talker

Posts: 10
Name: Travis Bales
Trades: 0
the
PHP Code:
"".Get_Username2('\\1').""
is what wont work.


PHP Code:
$out1 preg_replace("/\[user\](.*)\[\/user\]/Usi""".Get_Username2('\\1').""$out1); 
tbales is offline
Reply With Quote
View Public Profile
 
Old 03-08-2010, 11:51 AM Re: Preg_Replace and a function HELP
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
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.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 03-08-2010, 05:08 PM Re: Preg_Replace and a function HELP
Novice Talker

Posts: 10
Name: Travis Bales
Trades: 0
um, how might i do that exactly. im new with this preg replace.
tbales is offline
Reply With Quote
View Public Profile
 
Old 03-08-2010, 05:17 PM Re: Preg_Replace and a function HELP
Novice Talker

Posts: 10
Name: Travis Bales
Trades: 0
never mind i got this thank you alot.
tbales is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Preg_Replace and a function HELP
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.40736 seconds with 12 queries