preg_replace(array_map(function($arg) { return '/\b'. preg_quote($arg) . '\b/'; 
}, $killarray), ' ', makeutf8($prodname));

That uses closures so requires PHP 5.3. If you can't use that, move the 
function elsewhere, give it a name and pass that name as a string to 
array_map().

What this is doing is using the word boundary class to only match complete 
words. array_map() just loops over the given array, applies the given function 
to each item and returns all the return values in an array.

On 21/05/2011, at 2:26 PM, Admin wrote:

> 
>       Possibly OT, but think this group may have the solution...
> 
>       Given a variable of $prodname = "Jane and the Dragon : Fair Weather 
> Friends";
> 
>       And the operation code:
>               $killarray = array('and', '&', 'the', 'of', '-', ':', '.', '?', 
> '\'', '!', '(', ')');
>               $linkname = str_replace(' ', '_', str_replace($killarray," 
> ",makeutf8($prodname))); // Removes all surplus non-essential pieces, and 
> inserts http-safe spacers
>               while(strpos($linkname,'__') !== FALSE) {
>                       $linkname = str_replace('__', '_', $linkname); // 
> Remove multiple 'spacers'
>               }
> 
>       I get a result of $linkname = "Jane_Dragon_Fair_Wear_Friends"
> 
>       As you can see, it's stealing the "the" out of "Weather" and making it 
> "Wear"...
> 
>       If I include spaces in the $killarray items, the whole thing turns even 
> worse, with virtually no _ separators...
> 
>       I have tried having 'the ' and ' the' (ditto for other words in the 
> $killarray too) but then it still does the same thing with words such as 
> 'anders', 'sand', 'offer', 'theory' and 'menthe'...
> 
>       Can anyone please assist me, as this is causing me to go prematurely 
> bald! -lol-
> 
>       Perhaps some craftily-crafted Regex would solve it, but that's way 
> beyond me...
> 
>       Cheers...
> 
> 
> 
> 
> ---
> Karl
> www.KIWIreviews.co.nz ... Where Your Views Count
> Please consider the environment before printing this email
> 
> For regular updates and advance notice of special events and review goods, 
> why not join us on
> 
> Facebook : http://www.KIWIreviews.co.nz/facebook
> or
> Twitter : http://www.KIWIreviews.co.nz/twitter
> 
> KIWIreviews accepts no responsibility for changes to this email, or for any 
> attachments, after its transmission from the KIWIreviews server. Thank you.
> 
> - - - - - - - - - -
> We use CourierPost for all of our freight delivery requirements.
> - - - - - - - - - -
> 
> -- 
> NZ PHP Users Group: http://groups.google.com/group/nzphpug
> To post, send email to [email protected]
> To unsubscribe, send email to
> [email protected]

---
Simon Welsh
Admin of http://simon.geek.nz/

Who said Microsoft never created a bug-free program? The blue screen never, 
ever crashes!

http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e

-- 
NZ PHP Users Group: http://groups.google.com/group/nzphpug
To post, send email to [email protected]
To unsubscribe, send email to
[email protected]

Reply via email to