sniped22 Posted May 31, 2007 Share Posted May 31, 2007 $usernam = substr($pokerhand, 9, $pos2-9); $username ="<font color='blue'>$usernam:</font>"; $text_ou = preg_replace("/$usernam/", $username, $text_out); because $usernam is literally the section of string at a certain position i cant replace more than just the first instance of $usernam. Is there another way to get a string that will be different for each user. It will always be after the words "dealt to" but I cant use substr and strpos. There has to be another way. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/53796-solved-number-of-replacements/ Share on other sites More sharing options...
per1os Posted May 31, 2007 Share Posted May 31, 2007 Can you post what the input is and what you want the output to be? Quote Link to comment https://forums.phpfreaks.com/topic/53796-solved-number-of-replacements/#findComment-265890 Share on other sites More sharing options...
sniped22 Posted May 31, 2007 Author Share Posted May 31, 2007 This is just a portion of the input, as the input is very long: *** HOLE CARDS *** Dealt to redHAWKdown [Jc Ah] rafema: calls 20 redHAWKdown: raises 20 redhawkdown is what i want to be in the $usernam variable i want the output to be the same thing, just with redHAWKdown in blue text. I think this would be quite simple, i just cant figure it out Quote Link to comment https://forums.phpfreaks.com/topic/53796-solved-number-of-replacements/#findComment-265892 Share on other sites More sharing options...
per1os Posted May 31, 2007 Share Posted May 31, 2007 I am not very good with regex, but this should work <?php $input = '*** HOLE CARDS *** Dealt to redHAWKdown [Jc Ah] rafema: calls 20 redHAWKdown: raises 20 *** HOLE CARDS *** Dealt to refema [Jc Ah] redHAWKdown: calls 20 refema: raises 20'; list(,$info) = spliti("dealt to ", $input); list($usernam) = split(" [", $info); // if error do \[ instead of [ $username ="<font color='blue'>$usernam:</font>"; // To loop through it grabbing all names tryy this: $info = spliti("dealt to ", $input); array_shift($info); foreach ($info as $name) { list($usernam) = split(" [", $info); // if error do \[ instead of [ $username[] = "<font color='blue'>$usernam:</font>"; } echo '<pre>',print_r($username),'</pre>'; ?> There is probably a nicer way to do it with preg, but eh I like my way =) Quote Link to comment https://forums.phpfreaks.com/topic/53796-solved-number-of-replacements/#findComment-265893 Share on other sites More sharing options...
sniped22 Posted June 1, 2007 Author Share Posted June 1, 2007 This way didn't work, and quite frankly, i didn't understand it. I replaced all the variable names and such. Maybe there is a way to put the output of a variable into an array of characters and then use that array as the preg_replace pattern. Quote Link to comment https://forums.phpfreaks.com/topic/53796-solved-number-of-replacements/#findComment-265962 Share on other sites More sharing options...
Caesar Posted June 1, 2007 Share Posted June 1, 2007 <?php preg_match_all('/Dealt to ([aA-zZ0-9]+)/', $input, $usrname); //$usrname Array will output: //Array ( [0] => Dealt to redHAWKdown [1] => redHAWKdown ).....etc ?> Quote Link to comment https://forums.phpfreaks.com/topic/53796-solved-number-of-replacements/#findComment-265965 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.