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
Switch to threaded view of this topic Create a new topic Submit Reply
help with regular expressions [message #174320] Sat, 04 June 2011 16:55 Go to next message
Innerlab is currently offline  Innerlab
Messages: 2
Registered: June 2011
Karma: 0
Junior Member
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.

Thanks in advance.
_______________________
Eduardo Gomez
Re: help with regular expressions [message #174321 is a reply to message #174320] Sat, 04 June 2011 17:01 Go to previous messageGo to next message
Innerlab is currently offline  Innerlab
Messages: 2
Registered: June 2011
Karma: 0
Junior Member
Hello. On the previous post, I made an error:

> 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>

The last line should have read:

<a href="http://Name_of_URL">Name_of_URL</a>

My apologies...
_______________________
Eduardo Gomez
Re: help with regular expressions [message #174328 is a reply to message #174320] Sat, 04 June 2011 22:14 Go to previous messageGo to next message
jeff is currently offline  jeff   
Messages: 8
Registered: May 2005
Location: Toronto
Karma: 0
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
>
>
>
>
>
Re: help with regular expressions [message #174345 is a reply to message #174320] Mon, 06 June 2011 14:06 Go to previous message
Nick Wedd is currently offline  Nick Wedd
Messages: 1
Registered: June 2011
Karma: 0
Junior Member
On 04/06/2011 17:55, 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.

Can you give an actual example of a string that you might want to
process, and of what you want it converted to?

Nick
--
Nick Wedd
nick(at)maproom(dot)co(dot)uk
  Switch to threaded view of this topic Create a new topic Submit Reply
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: Thu Nov 28 02:01:14 GMT 2024

Total time taken to generate the page: 0.02502 seconds