[wp-hackers] Passing Key but Not Value?

Otto otto at ottodestruct.com
Tue Sep 28 15:57:24 UTC 2010


Well, the $acronyms array doesn't have the replacement values in it,
so $matches[2] doesn't have anything in it. Nor could it, in fact,
because that's not what you're matching on anyway.

Pretty much, you're just doing it wrong. Try something more like this:

$arr_tmp = array(
'LAN' => 'Local Area Network',
'DHCP' => 'Dynamic Host Control Protocol',
'SSH' => 'Secure Shell',
'FTP' => 'File Transfer Protocol',
'SFTP' => 'Secure File Transfer Protocol',
);
foreach ($arr_temp as $s=>$r) {
$search[] = $s;
$replace[] = "<acronym title='$r'>$s</acronym>";
}
$text= str_replace($search, $replace, $text);

You'll also find that that is one heck of a lot faster than using
regular expression functions.

-Otto



On Tue, Sep 28, 2010 at 10:27 AM, Guy <wphax at nullamatix.com> wrote:
> y0,
>
> The following snippet of code exists in my theme's functions.php. The
> code works as intended with the exception of the Value in arr_tmp. The
> idea is to scan the_content for a list of defined acronyms and replace
> the acronym in the_content with: <acronym title="The Acronym
> Title">TAT</acronym>. Seems simple enough, but the title="" just isn't
> showing up...
>
> What am I missing/doing wrong here? Obviously I'm not a developer,
> just pretend to be on TV :P
>
> Code:
> http://sprunge.us/ZEVY?php
>
> Regards,
>
> Guy
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>


More information about the wp-hackers mailing list