Jump to content

Quick question on finding if its a link in a string


BillyBoB

Recommended Posts

I have a news database and i was wondering if i could somehow make it where when if fetches the array if it could search it and put it in a <a href=$link >$link</a> and make it where if it allready has the tag <a href= > and </a> then do nothing this is probably a longer anwser but if som1 could plz help that would be much appreciated
[code]
<?php
// assuming your data looks like this vs. this:
// http://www.blah.com vs. <a href='http://www.blah.com'>http://www.blah.com</a>

// example
$data = "http://www.blah.com";

// data have '<a' in it already? do nothing. It doesn't? add it on
$data = (stripos($data, "<a")) ? $data :  "<a href = '$data'>$data</a>";
[/code]
uh..okay..well you didn't say anything about that in your OP.  And even now you're not being very specific.  The impression I got is that you have a chunk of data and it has a url in it somewhere but it may or may not have href tags around it, so if it doesn't, then wrap the url in href tags.  That's what my example does.  If you have an array of data, just put the code in a loop that checks each element.

How about you make an example list of what your actual data looks like and post it here, showing [i]every[/i] example of what it should look for and change, vs. not change.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.