FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » help with regular expressions
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: help with regular expressions [message #174328 is a reply to message #174320] Sat, 04 June 2011 22:14 Go to previous messageGo to previous message
jeff is currently offline  jeff   
Messages: 8
Registered: May 2005
Location: Toronto
Karma:
Junior Member
On 6/4/2011 12:55 PM, Innerlab wrote:
> Hello. I'm trying to parse pages from wikipedia. Although I'm not
> that good with PHP, such scripts are more available on the web than -
> lets say- ASP/ VBscript.
>
> I have a PHP script that returns links within wikipedia pages as:
>
> [url=_Name_of_URL_] Name_of_URL [/url]
>
> So, with regex I must parse the above to construct links like:
>
> <a href="http://URL">Name_of_URL</a>
>
> I know the preg_replace( ) function is the one to use, but honestly, I
> cannot figure out what regex I must use.
>
> I'd appreciate any guidance on this matter.

It'll be easier if you catch the matches with preg_match and assemble
what you need out of that:

http://php.net/manual/en/function.preg-match.php

Note that square brackets will need to be escaped as those signify
character groups in a regex.

$regex = '/\[(.*?)\]/';

preg_match($regex,'[url=Name_of_URL]Name_of_URL[/url]',$matches);

echo $matches[1]; prints Name of URL

Jeff
>
> Thanks in advance.
> _______________________
> Eduardo Gomez
>
>
>
>
>
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Previous Topic: syntax question
Next Topic: ONLINE BACKUP IS VERY MUCH ESSENTIAL FOR SECURE YOUR DATA
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Dec 01 04:10:13 GMT 2024

Total time taken to generate the page: 0.04091 seconds