[wp-hackers] Passing Key but Not Value?
Chris Jean
gaarai at gaarai.com
Tue Sep 28 15:54:40 UTC 2010
Here's what I came up with: http://sprunge.us/ZUOU
Your basic problem is that you stored the description no where. Your
code was trying to find the description in the regular expression match,
which doesn't make sense as the regex wouldn't match a description that
didn't exist in the original text.
So, I turned the $acronyms global into an associative array that stores
the acronym and the description. This is then used to generate an array
of regular expressions that is fed to the preg_replace_callback. The
callback then uses the global $acronyms array to put everything together.
While making the changes, I removed the 's' modifier for the regular
expression as it wasn't needed, used preg_quote to ensure that the
acronym text didn't break the regular expression, and added code to
handle case differences in the matches. The output will normalize the
capitalization of the match to fit the capitalization of the acronym in
the array, so instances of "SSH", "ssh", or "sSH" will all print as "SSH".
Chris Jean (AKA gaarai& chrisbliss18)
Coder for http://ithemes.com/
http://gaarai.com/
@chrisjean
On 09/28/2010 10:27 AM, Guy 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