Jump to content

Get url out of plain text


Yves

Recommended Posts

Hi,

 

I have an free articles directory. Webmasters can freely reprint articles for their website, ezine or newsletter. Each article has a Copy & Publish Article page with both HTML and plain text versions of the article. Each article contains an author resourse box with up to 3 links linking to the webpages the authors whats to rank for in the searchengines. Now, this author resourse box is just plain text in the mysql. See example below.

 

First I would like to add I did about 10 different searches to spair you guys a new topic to no avail. I hope you're kind enough to help me out. Thanks.

 

What I like to achieve is making strings like these

 

Gregg Hall is an author living with his 18 year old son in Jensen Beach, Florida. Find more about Xbox games as well as <a href="http://www.nsearch.com/?k=Computers">Video Game Systems</a> at <a href="http://www.nsearch.com">http://www.nsearch.com</a>

 

strings like these

 

Gregg Hall is an author living with his 18 year old son in Jensen Beach, Florida. Find more about Xbox games as well as [http://www.nsearch.com/?k=Computers]Video Game Systems at [http://www.nsearch.com]

 

As you can see I would like html 'href' links wrapped in [ ]. But if html 'href' links are the same as the display text, don't display any text behing the [] (see 2nd link in quote above)

 

EDIT: $html is this plain text string

 

Thank you.

Link to comment
Share on other sites

That didn't fully do it. It outputted this:

 

Gregg Hall is an author living with his 18 year old son in Jensen Beach, Florida. Find more about Xbox games as well as Video Game Systems at http://www.nsearch.com

 

There are not brackets and the anchored link wasn't transformed.

PS: I edited my 1st code quote in 1st post to show that href's can contain any kind of link.

Link to comment
Share on other sites

I found a great tutorial on preg_replace. At least I thought I did. And came up with this:

 

<?php 
$urlfind = '/(<a href=")(.*)(">)(.*)(<\/a>)/';
$urlreplace = '[${2}]${4}';
$html = preg_replace($urlfind, $urlreplace, $html);
?>

 

But it didn't work either. I'm not getting there. :/

Link to comment
Share on other sites

just wondering if this gets you any where try t his for me

<?php
$file = "http://www.testsite.com";
$data = file_get_contents($file);
if(!empty($data){
   $data = strip_tags($data,"<a>");
}
$data = str_replace("\n","",$data);
$data = str_replace("</a>","\n",$data);
$data = explode("\n",$data);
print_r($data);
?>

see what it says for you just curious

Link to comment
Share on other sites

I see. Well, it says:

 

Warning: file_get_contents() [function.file-get-contents]: php_network_getaddresses: getaddrinfo failed: Temporary failure in name resolution in /.../test.php on line 11

Warning: file_get_contents(http://www.testsite.com) [function.file-get-contents]: failed to open stream: Connection timed out in /.../test.php on line 11
Array ( [0] => )

Link to comment
Share on other sites

I see. Nerd joke. Get out more often.

 

I think there is no reason for me, nor anyone to stick around here any longer. Thank you Ken2k7 for your kind help. I appreciate it.

It was hardly a joke, and even if it was, the joke was on you anyway.

People are here to help, not dish out code. So when someone provides you the code the least you can do is actually look at it and try to figure out what it is actually doing!

Link to comment
Share on other sites

I did look at it. I just don't know what 'file_get_contents' is. Because you laughed, I thought it a command to get information about the data, which is the testsite.com, a site I donnot own. So I though it could not get that information because I'm not the owner. ~ hence a joke pulled on me.

 

I first didn't think someone with so many post would do that. But if that is the case, well then, I think its obvious for me to leave.

 

Don't expect people who ask question to allready know as much as you do. And don't assume they don't look at the code. Believe me; those that don't look at the code must be less then 1% of visitors here.

Link to comment
Share on other sites

I did look at it. I just don't know what 'file_get_contents' is. Because you laughed, I thought it a command to get information about the data, which is the testsite.com, a site I donnot own. So I though it could not get that information because I'm not the owner. ~ hence a joke pulled on me.

 

I first didn't think someone with so many post would do that. But if that is the case, well then, I think its obvious for me to leave.

 

Don't expect people who ask question to allready know as much as you do. And don't assume they don't look at the code. Believe me; those that don't look at the code must be less then 1% of visitors here.

 

Maybe you're a bit to sensitive. I'm sure anyone else would have laughed when they realised the simple error they made.

You're just going a bit OTT.

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.