03laceys Posted November 29, 2010 Share Posted November 29, 2010 Ok so i am highlighting the text in explore using... function highlightWords($string, $words) { foreach ( $words as $word ) { $string = str_ireplace($word, '<span class="highlight_word">'.$word.'</span>', $string); } /*** return the highlighted string ***/ return $string; } $string = 'http://xvon.info/game/register.php?REF=$userid'; $words = array('http://xvon.info/game/register.php?REF=$userid'); $string = highlightWords($string, $words); Problem with using this is that it dosn't display the actuall userid it just display the code $userid How am i able to highlight this particular text? Thanks. Quote Link to comment Share on other sites More sharing options...
Equinox Posted November 29, 2010 Share Posted November 29, 2010 function highlightWords($string, $words) { foreach ( $words as $word ) { $string = str_ireplace($word, '<span class="highlight_word">'.$word.'</span>', $string); } /*** return the highlighted string ***/ return $string; } $string = 'http://xvon.info/game/register.php?REF='.$userid.''; $words = array('http://xvon.info/game/register.php?REF='.$userid.''); $string = highlightWords($string, $words); Quote Link to comment Share on other sites More sharing options...
The Monk Posted November 29, 2010 Share Posted November 29, 2010 As posted above by Equinox. '.$var.'/".$var." The default for MCC is to wrap the variable with { & }. I have always used the other technique but im un-aware of any differences. Quote Link to comment Share on other sites More sharing options...
Equinox Posted November 29, 2010 Share Posted November 29, 2010 It's not default with MCC, you say it as if MCC is a different language completely to PHP. $string = ' blah '; The reason you have to define the variable in this instance is down to the single quotes, single quotes will not look for a variable within a string whereas double quotes will, for example: $string = "http://xvon.info/game/register.php?REF=$userid"; That would work fine. Quote Link to comment Share on other sites More sharing options...
The Monk Posted November 29, 2010 Share Posted November 29, 2010 By default I mean almost every script in the original unedited versions of MCC(default) uses { & } around the variables. Quote Link to comment Share on other sites More sharing options...
03laceys Posted November 29, 2010 Author Share Posted November 29, 2010 Thank you for the replies, and not just posting the fix. Was nice to have a post explaining why it was doing it and how to fix. Thank you. Quote Link to comment 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.