Jump to content

[SOLVED] number of replacements


sniped22

Recommended Posts

$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

Link to comment
https://forums.phpfreaks.com/topic/53796-solved-number-of-replacements/
Share on other sites

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

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 =)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.