Jump to content

URL parse


mraza

Recommended Posts

Hi i am trying to parse content of page, what i am having problem is if i have a word like this;

 

<a href="foo.com">Click...Ere</a>

 

i could not pass it through on end result i get something like this

[url]Click...Ere[/url]

means the word will display like surround url tag not actully getting the hyperlink.

 

please any help what i am missing here is the complete code:

   '~<img\b[^>]+\bsrc\s?=\s?([\'"])(.*?)\1[^>]*>~is' => '[img=$2]',
   '~<b\b[^>]*>(.*?)</b>~is' => '[b]$1[/b]',
   '~<a(.*?)>(.*?)<\/a>~is' => '[url]$2[/url]',

Thanks

Link to comment
Share on other sites

Thanks for the reply its working when i run its alone but when i use it in array, here i am also having images with link to them so when its parsed the image will disappear and the link will appear if i use this code:

 

$replace = array(

// image and bold bbc code escaped

   '~<img\b[^>]+\bsrc\s?=\s?([\'"])(.*?)\1[^>]*>~is' => '',
   '~<b\b[^>]*>(.*?)</b>~is' => '[b]$1[/b]',

// This is your code if i add image will not display as a 
// link but that will also become a hyper link

   '~<a[^>]+href="(.*?)"[\s\b\t]*>(.*?)<\/a>~is'=> '[url ]$1[/url]'
);

 

Thanks for any help

Link to comment
Share on other sites

hi i tried this and it worked:

 

   '~<a[^>]+href="(.*?)"[\s\b\t]*>(.*?)<\/a>~is'=> '[url=$1]$2[/url]'

but now the problem is the link become like this how to remove that extra  " target="_blank        ..thanks :

 

http://foo.html" target="_blank

Link to comment
Share on other sites

Not tested as you didn't really give a full example of what you require, but I think this is along the lines of what your after...

 

$pattern = '~<a[^>]+href=("|\')([^\1]*?)\1[^>]*>(.*?)</a>~is';
$replace = '[url=$2]$3[/url]';

Link to comment
Share on other sites

Thank you cags i was exactly looking for that but it come in my mind if it was possible it will see the words in a tag:

 

" target="_blank

 

and replace it to:

 

target="_blank"

 

i dont wants to use str_ireplace if could be done via expression. but if not that's ok, it just come in mind if it could be via expression.

 

Edit: and btw Congrats for guru badge you deserved it you are always a big help . Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.