Hello,
I am in need of a method to extract a dynamic value between constant delimiters from a string and assign it to a variable.
The application: I want to be able to have my users write something like :news204: which would be replaced with the HTML:
<a href="http://site.com/news/204">[News item 204]</a>
I'm assuming I could use a regex to accomplish this. In my head it would work something like:
ereg_replace(":news" . [B]( Assign whatever value is here to $item )[/B] . ":", "<a href=\"http://site.com/news/" . [B]$item[/B] . " /\">[News item " . [B]$item[/B] . "]</a>", $page)
with another part to determine if the $item is 3 or 4 integers or less, sanitize and whatnot. The whole point of this is to avoid using any database query, other file, or preset variable ( I don't want the script to look up how many articles there are ) - it would be up to the user to get the number right: if he or she types :news392: and there is no article number 392 I don't care, I just want the link made anyway. The reason I don't want this is because I would like to be able to apply for arbitrary non-integer values as well ( i.e. ":search-electronics-:" to create a link that would lead to a search for "electronics" ).
I hope that's not too specific, I just want to make my use of this method clear. =)
I appreciate your time.