I wrote a plugin named "Simple Smart Links" to replace an older no-longer-working wordpress plugin that I'd been relying on heavily (it makes links out of text like [title -> href]. My plugin relies on regex, and it's not quote working properly.
The code is:
function replace_the_text($content) {
$content = ereg_replace("\[([0-9a-zA-Z\(\)\'\"\? ]*)[ ]*\-\>[ ]*([0-9a-zA-Z:/\.\_\-\'\(\)\?\=]*)\]", '<a href="\2">'.trim('\1').'</a>', $content);
return $content;
}
add_filter('the_content', 'replace_the_text');
The issue is that despite the trim, spaces sometimes end up in the link. Using this following test post:
[hello -> foo] this is test 1.
[hello->foo] this is test 2.
[hello ->foo] this is test 3.
[hello -> foo]
[hello -> foo]
...I end up with:
<p><a href="foo">hello </a> this is test 1.<br />
<a href="foo">hello</a> this is test 2.<br />
<a href="foo">hello </a> this is test 3.<br />
<a href="foo">hello </a><br />
<a href="foo">hello </a></p>
Notice that test 2 is the only one that doesn't end up with spaces. So the space before the arrow is being greedily matched, which is fair enough - but the trim is supposed to take care of that. Anybody shed any insight into what's going on?
Thanks