Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.