The Web Design Group

... Making the Web accessible to all.

Welcome Guest ( Log In | Register )

> Exact Match, How to find exact (whole only) match
Dag
post Apr 8 2020, 06:27 AM
Post #1


Advanced Member
****

Group: Members
Posts: 107
Joined: 24-October 06
Member No.: 549



I need to find and replace strings inside the text. In this case, text is in the array format. I don't want to replace parts of the string if full string do not match. Samples:
CODE

$find = array('Dominican Republic','Netherlands Antilles','Netherlands','Republic');
$replace = array('Доминиканская Республика','Нидерландские Антильские острова','Нидерланды','Република');
$text = array('Netherlands','Caribbean Netherlands','Republic','Dominican Republic','Netherlands Antilles','My Personal Republic');
$textNew = str_replace($find,$replace,$text);

Result is
CODE

Array
(
    [0] => Нидерланды
    [1] => Caribbean Нидерланды
    [2] => Република
    [3] => Доминиканская Республика
    [4] => Нидерландские Антильские острова
    [5] => My Personal Република
)

Walking through string by string... here is one string only:
CODE

$text = array('Caribbean Netherlands');

Result is
CODE

Array
(
    [0] => Caribbean Нидерланды
)

Regexp "/b" didn't help.
Any ides about this? Is it well known issue and is it very simple to be solved?
Thanks in advance.
User is offlinePM
Go to the top of the page
Toggle Multi-post QuotingQuote Post

Posts in this topic


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



- Lo-Fi Version Time is now: 6th May 2024 - 09:22 PM