|
-
Oct 11th, 2006, 02:22 AM
#1
Thread Starter
Fanatic Member
the first instence of string from array A in string B
I wish to write a process that will automatically act on a block of text.
My first idea was to take the list of words and phrases and build a regex part like this [word1|word2|etcetc...] which would allow me to convert each word to a hyperlink.
However if more than one instence of any word is made into a link this will cause problems for the indexer which will list the block of text twice...
So I need to find only the first example of each word.
However, I need to be as fast as possible as each such lot of code slows down the text addition process and it is already a bit bogged.
Q. So what is the fastest way to do this?
Q. Is there a reasonably efficient way to do this and detect for user added links? (does it make any difference that the links could come in BBish, HTML or custom tag markup?)
Any clues at all would be helpfull at this stage.
-
Dec 8th, 2007, 10:06 AM
#2
Thread Starter
Fanatic Member
Re: the first instence of string from array A in string B
I'm doing this in php. The idea being to hyper link the first instance of any word for the list in a body of HTML that might contain unprocessed BB/wiki/custom markup.
I need to be able to check I am not wrapping an a-href arround markup or existing a-href...
-
Dec 9th, 2007, 12:47 AM
#3
Re: the first instence of string from array A in string B
you could try just using explode, and then loop through the array.
PHP Code:
$string = "word1|word2|word3";
$words = explode('|', $string);
$i=0;
while($i < count($words)) {
echo "<a href='whatever.php?keyword={$words[$i]}'>{$words[$i]}</a>";
$i++;
}
that code will loop through $string and print a link for all of the words in the array separated by the |
EDIT:
Here is a working example: http://www.subsoft.net/vbf/array_test.php
Last edited by dclamp; Dec 9th, 2007 at 12:55 AM.
My usual boring signature: Something
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|