Lamez Posted October 15, 2008 Share Posted October 15, 2008 I have this script, which madTechie help write. What it does is find the a url in a blob of text, then it checks the database for the link, if it exist it pulls the encrypted link as the id, and makes a link to my ELC. If it does not it makes a new id which is the encrypted link, and it stores it in the DB, and makes a link to the ELC. Well if I post a link beside each other, it comes out as one link. Why? here is a test page: http://links.krazypicks.com/test.php try putting in a single link such as: www.phpfreaks.com. then try putting in multiple links beside each other, such as: www.phpfreaks.com www.google.com Here is the code, can you guys please explain the problem to me? <?php $HTML = $_POST['html']; $result = preg_replace_callback('%\b((?:www\.|http://www\.|http://).*)\b%si', 'UpdateDB', $HTML); echo "<br>Final Output<br>"; echo $result; function UpdateDB($Add) { $id = md5($Add[1]); $url = $Add[1]; //DB Connection... $sql = mysql_query("SELECT * FROM `url_list` WHERE `url`='".$url."'"); if (!mysql_num_rows($sql) >= 1){ mysql_query("INSERT INTO url_list (ID, URL) values ('$id','$url')"); }else{ $r = mysql_fetch_array($sql); $id = $r['id']; } return "<a href=\"http://links.krazypicks.com?url=$id\">Link</a> "; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/128469-solved-new-hour-new-problem/ Share on other sites More sharing options...
suzzane2020 Posted October 15, 2008 Share Posted October 15, 2008 Hi, Your code does not have the function to split more than 1 url. Everything is taken as a single string. You could use the explode function. Have a note for the users that they need to use a separator like comma for the urls Quote Link to comment https://forums.phpfreaks.com/topic/128469-solved-new-hour-new-problem/#findComment-665806 Share on other sites More sharing options...
Lamez Posted October 15, 2008 Author Share Posted October 15, 2008 Could I just use a space in the explode function? Quote Link to comment https://forums.phpfreaks.com/topic/128469-solved-new-hour-new-problem/#findComment-665813 Share on other sites More sharing options...
Lamez Posted October 15, 2008 Author Share Posted October 15, 2008 Also, where should I put the explode function? Quote Link to comment https://forums.phpfreaks.com/topic/128469-solved-new-hour-new-problem/#findComment-665816 Share on other sites More sharing options...
suzzane2020 Posted October 15, 2008 Share Posted October 15, 2008 Yes you can use a space. Use it just after u get the post value. $HTML = $_POST['html']; $url_array = explode(" ",$HTML); Quote Link to comment https://forums.phpfreaks.com/topic/128469-solved-new-hour-new-problem/#findComment-665818 Share on other sites More sharing options...
Lamez Posted October 15, 2008 Author Share Posted October 15, 2008 so in order to take it out of the array, well poop, how do I take it out of the array? Quote Link to comment https://forums.phpfreaks.com/topic/128469-solved-new-hour-new-problem/#findComment-665823 Share on other sites More sharing options...
suzzane2020 Posted October 15, 2008 Share Posted October 15, 2008 Thers the foreach loop. I guess you would have to go through a few basics to get a smooth flow in coding. php.net is the best place for a start Quote Link to comment https://forums.phpfreaks.com/topic/128469-solved-new-hour-new-problem/#findComment-665847 Share on other sites More sharing options...
Lamez Posted October 15, 2008 Author Share Posted October 15, 2008 well I am always learning something new, this however is really really new to me, I can code a php page with no problem, but somethings like this are completely new to me. So you are saying to look at a foreach loop. I will do that tomorrow! Thank you very much for your time. Quote Link to comment https://forums.phpfreaks.com/topic/128469-solved-new-hour-new-problem/#findComment-665850 Share on other sites More sharing options...
Lamez Posted October 15, 2008 Author Share Posted October 15, 2008 I figured it out! Thank you for the suggestion on the foreach loop! code: <?php $HTML = $_POST['html']; $HTML = explode(" ",$HTML); $result = preg_replace_callback('%\b((?:www\.|http://www\.|http://).*)\b%si', 'UpdateDB', $HTML); echo "<br>Final Output<br>"; //echo $result; //print_r($result); foreach($result as $val){ echo $val; } function UpdateDB($Add) { $id = md5($Add[1]); $url = $Add[1]; //DB Con... $sql = mysql_query("SELECT * FROM `url_list` WHERE `url`='".$url."'"); if (!mysql_num_rows($sql) >= 1){ mysql_query("INSERT INTO url_list (ID, URL) values ('$id','$url')"); }else{ $r = mysql_fetch_array($sql); $id = $r['id']; } return " <a href=\"http://links.krazypicks.com?url=$id\">Link</a> "; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/128469-solved-new-hour-new-problem/#findComment-665863 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.