Jump to content

replacing two words


RyanSF07

Recommended Posts

Hello,

 

This code:

$textlevel= $row['level_text'];
$oldlevel = array("Intermédio", "Intermédio avançado");
$newlevel = array("intermediate", "high_intermediate");
$textlevel = str_replace($oldlevel , $newlevel , $textlevel);

 

spits out "intermediate avançado" instead of "high_intermediate"

 

How do I join "Intermédio" and "avançado" so that "Intermédio avançado" is in fact replaced with high_intermediate instead of only the first work replaced?

 

thank you for your help,

Ryan

Link to comment
https://forums.phpfreaks.com/topic/273075-replacing-two-words/
Share on other sites

Hey bud, you can give this a try:

<?php

$textlevel= "Intermédio";
$words = str_word_count($textlevel,0,"éç");

if($words == 2)
{
$textlevel = str_replace("Intermédio avançado","high_intermediate",$textlevel);
}
else
{
$textlevel = str_replace("Intermédio","intermediate",$textlevel);
}

echo $textlevel;

?>

 

Just wrote it works pretty well.

 

EDIT: LOL just do what jessica said. :pirate:

 

Hope this helps you,

 

Regards,

 

L2c.

Link to comment
https://forums.phpfreaks.com/topic/273075-replacing-two-words/#findComment-1405232
Share on other sites

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.