str_replace supports arrays as search/replace
str_replace($wordList, $replaceList, $string);
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello, I want to use str_replace or any other function can do the same effect. to do this // let's say that I have this string
AD2460 is a browser-based Sci-Fi strategy MMORPG set in a persistent world. the game draws from real time Strategy titles and the developer's own influential 2001 web game, planetarion. AD2460 sees humans scattered all over the universe after the discovery of gates allowing travel through space with cultures, traditions, factions, and policies developing in their new locations.
and I have some world inside of it I want to change with other words.
$wordArray = array('ad2460', 'sci-fi', 'strategy');
I want to check if this word inside of the array is in the string if the words exist replace it with if sci-fi exists to replace it with sci-fi and so on how can I do so.
I've tried to use foreach like this
echo str_replace($word, "<strong>" . $word . "</strong>", $string);
}
this just echo the string multiable times if 2 words from the array exists on the string will echo the string again and i don't want that and i also tried this
$string = str_replace($word, "<strong>" . $word . "</strong>", $string);
}
echo $string;
this only replace the last element on the array this is the only one that works for me but it's too messy and this is the one am using right now
<?php
$Info = str_replace(strtolower($row['game_name']),
'<strong class="text-dark text-capitalize">'.$row["game_name"].'</strong>', strtolower($reviewRow['gameOverview']));
$Info = str_replace(" mmorpg ",
'<strong class="text-info text-capitalize"><a href="'.BASE_URL.'/browser-games/mmorpg" rel="tag" class="text-info"> MMORPG </a></strong>', $Info);
$Info = str_replace(" anime ",
'<strong class="text-info text-capitalize"><a href="'.BASE_URL.'/browser-games/anime" rel="tag" class="text-info"> Anime </a></strong>', $Info);
$Info = str_replace(" action ",
'<strong class="text-info text-capitalize"><a href="'.BASE_URL.'/browser-games/action" rel="tag" class="text-info"> Action </a></strong>', $Info);
$Info = str_replace(" fantasy ",
'<strong class="text-info text-capitalize"><a href="'.BASE_URL.'/browser-games/fantasy" rel="tag" class="text-info"> Fantasy </a></strong>', $Info);
$Info = str_replace(" fps ",
'<strong class="text-info text-capitalize"><a href="'.BASE_URL.'/browser-games/fps" rel="tag" class="text-info"> FPS </a></strong>', $Info);
$Info = str_replace(" mobile ",
'<strong class="text-info text-capitalize"><a href="'.BASE_URL.'/mobile-games/" rel="tag" class="text-info"> Mobile </a></strong>', $Info);
$Info = str_replace("mobile game",
'<strong class="text-info text-capitalize"><a href="'.BASE_URL.'/mobile-games/" rel="tag" class="text-info"> Mobile Game </a></strong>', $Info);
$Info = str_replace(" fps ",
'<strong class="text-info text-capitalize"><a href="'.BASE_URL.'/browser-games/fps" rel="tag" class="text-info"> TPS </a></strong>', $Info);
$Info = str_replace(" sci-fi ",
'<strong class="text-info text-capitalize"><a href="'.BASE_URL.'/browser-games/sci-fi" rel="tag" class="text-info"> Sci-Fi </a></strong>', $Info);
$Info = str_replace(" scf fi ",
'<strong class="text-info text-capitalize"><a href="'.BASE_URL.'/browser-games/scf-fi" rel="tag"> Sci-Fi </a></strong>', $Info);
$Info = str_replace(" simulation ",
'<strong class="text-info text-capitalize"><a href="'.BASE_URL.'/browser-games/simulation" rel="tag" class="text-info"> Simulation </a></strong>', $Info);
$Info = str_replace(" sport ",
'<strong class="text-info text-capitalize"><a href="'.BASE_URL.'/browser-games/sport" rel="tag" class="text-info"> Sport </a></strong>', $Info);
$Info = str_replace(" strategy ",
'<strong class="text-info text-capitalize"><a href="'.BASE_URL.'/browser-games/strategy" rel="tag" class="text-info"> Strategy </a></strong>', $Info);
$Info = str_replace(" text based ",
'<strong class="text-info text-capitalize"><a href="'.BASE_URL.'/browser-games/text-based" rel="tag" class="text-info"> Text-Based </a></strong>', $Info);
$Info = str_replace(" text-based ",
'<strong class="text-info text-capitalize"><a href="'.BASE_URL.'/browser-games/text-based" rel="tag" class="text-info"> Text-Based </a></strong>', $Info);
$Info = str_replace(" cross platform ",
'<strong class="text-info text-capitalize"><a href="'.BASE_URL.'/mobile-games/" rel="tag" class="text-info"> Cross Platform </a></strong>', $Info);
$Info = str_replace(" cross-platform ",
'<strong class="text-info text-capitalize"><a href="'.BASE_URL.'/mobile-games/" rel="tag" class="text-info"> Cross Platform </a></strong>', $Info);
$Info = str_replace(" mmo ",
'<strong class="text-info text-capitalize"><a href="'.BASE_URL.'/browser-games/mmorpg" rel="tag" class="text-info"> MMO </a></strong>', $Info);
$Info = str_replace(" browser game",
'<strong class="text-info text-capitalize"><a href="'.BASE_URL.'/browser-games/" rel="tag" class="text-info"> Browser Game </a></strong>', $Info);
$Info = str_replace(" shooter ",
'<strong class="text-info text-capitalize"><a href="'.BASE_URL.'/browser-games/fps" rel="tag" class="text-info"> Shooter </a></strong>', $Info);
$Info = str_replace(" features",
'<strong class="text-dark h5 text-capitalize font-weight-bold"> Features </strong>', $Info);
$Info = str_replace(" feature ",
'<strong class="text-dark text-capitalize font-weight-bold"> Feature </strong>', $Info);
$Info = str_replace(" multiplayer",
'<strong class="text-dark text-capitalize font-weight-bold"> multiplayer </strong>', $Info);
$Info = str_replace(" main points ",
'<strong class="text-dark h5 text-capitalize font-weight-bold"> Features </strong>', $Info);
$Info = str_replace(" free-to-play ",
'<strong class="text-dark text-capitalize font-weight-bold"> Free-To-Play </strong>', $Info);
$Info = str_replace(" tactical ",
'<strong class="text-dark text-capitalize font-weight-bold"> tactical </strong>', $Info);
$Info = str_replace(" character",
'<strong class="text-dark text-capitalize font-weight-bold"> character </strong>', $Info);
$Info = str_replace(" event",
'<strong class="text-dark text-capitalize font-weight-bold"> Event </strong>', $Info);
$Info = str_replace(" gear ",
'<strong class="text-dark font-weight-bold"> gear</strong>', $Info);
echo $Info;
?>
can anyone give me a bitter way to do this
Please or to participate in this conversation.