Results 1 to 4 of 4
Thread: str_replace only once
Jun 12, 2001, 20:17 #1
- Join Date
- Jun 2001
- 0 Post(s)
- 0 Thread(s)
str_replace only once
We use a content admin system to post articles to a DB.
Upon submission, I want the script to search for the first instance of a proper name - check it against a set of data, and if there's a match, add an appropriate link.
1) This is partly simple if using a set of data around 100 names or so. Loop through each name in the list ... and if there's a match in the text, add the corresponding link:
foreach ($team_name as $key=>$value)
Can someone suggest the combination of functions I'm looking for. For example, if the team name "Bears" appears 3 times in an article, I only want to do the "str_replace" on the first instance.
Alternatively, can it be done with "ereg_replace"
2) Can someone suggest an alternative method of checking for matches. Let's say I want to check against a list of names that reside in a DB. Instead of just 100 team names, I want to check against 5,000 player names. I don't think I want to loop through every name looking for a match (as I'm doing above). I *could* do that -- but I would think there's a better way. I don't know.
Thank you.Adam W.
Web Developer / Columnist