PHP Code:
$string = 'Looking for marketers who want to work. Ready to change your life? Trevo offers one product - an all natural, vegan, kosher nutritional supplement with 174 nutraceuticals. Visit www.SoCal.trevobuilder.com for product info & to purchase. Find me on facebook at Trevo SoCal or @TrevoSoCal on twitter. Low start up, cost covers first 3 bottles or larger packages available. No registration fees. Start making money this week! Visit trevocorporate.com/coach/sjahr to register on the Presidential Elite team. Welcome to facebook.com.';
$new_string = '';
$string_explode = explode(' ',$string);
foreach($string_explode as $key){
$check = strpos($key,'.') !== false?weblink($key):$key.' ';
echo $check;
}
function weblink($test){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $test);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_MAXREDIRS, 10);
$data = curl_exec($ch);
$info = curl_getinfo($ch);
$code = $info['http_code'];
curl_close($ch);
$good_array = array(100,101,200,201,202,203,206,300,301,302,304);
if(in_array($code,$good_array)){
$add = preg_match('/http:\/\//',$test)?'':'http://';
return '<a href="'.$add.$test.'">'.$test.'</a> ';
}else{
return $test.' ' ;
}
}
FYI i added something to test if it does work. At the very end i added "Welcome to facebook.com." To test if the period would mess up my code and it doesnt. However, if it is ? ! or something weird then the website will not exists. I will have to fix that. - If you want me to fix this problem let me know. Its easy.
Another note: "trevocorporate.com/coach/sjahr" doesnt work so it will not place a link around the website.
Bookmarks