Lamez Posted October 13, 2008 Share Posted October 13, 2008 Ok, I want to make a new function to go along with my ELC, and I want it to search the string to see if it contains something like, www., http://www., or http:// then I want it to encrypt it(the whole URL\Link), add it to the DB(the encryption of the link), and add the regular link to the DB. Then I want it to take the link the user posted, and change the name, and link it to my ELC. Any idea what functions I need to look at, besides md5(), and sha1()? ELC = External Link Checker http://links.krazypicks.com Quote Link to comment https://forums.phpfreaks.com/topic/128188-solved-need-help-string-replace/ Share on other sites More sharing options...
MadTechie Posted October 13, 2008 Share Posted October 13, 2008 why not replace the link with a link to your sites link checker with the DB entry ID ie mylinkchecker.php?ID=10002 in the DB have 10002 as the ID of the record for website phpfreaks.com etc to find the URLs use a REGEX replce like this:~ <?php $HTML = "this is a test www.apple.com blar tesing http://apple.com blob http://www.apple.com hee "; $result = preg_replace_callback('%\b((?:www\.|http://www\.|http://).*?)\s%si', 'UpdateDB', $HTML); function UpdateDB($Add) { mysql_query("INSERT INTO mytable (URL) values ('$Add'')"); return "<a href=\"linkcheck.php?ID=".mysql_insert_id()."\">LINK</a>"; } ?> **UNTESTED** Quote Link to comment https://forums.phpfreaks.com/topic/128188-solved-need-help-string-replace/#findComment-664061 Share on other sites More sharing options...
Lamez Posted October 13, 2008 Author Share Posted October 13, 2008 cool looks useful, will this work, if I have a paragraph, with a link somewhere in the paragraph? example "Hello, my name is Awesome, you can call me cool. Here is a link to my website: www.mywebsite.com Have fun, and enjoy your day!" lol, will that bit of code be able to find the link in something like that. Quote Link to comment https://forums.phpfreaks.com/topic/128188-solved-need-help-string-replace/#findComment-664391 Share on other sites More sharing options...
Lamez Posted October 13, 2008 Author Share Posted October 13, 2008 ok I am getting this error: Warning: md5() expects parameter 1 to be string, array given in /html_test.php on line 11 Check out my link: KrazyPick Link :d This is the code I am using: <?php //DB Connection $HTML = $_POST['html']; $results = preg_replace_callback('%\b((?:www\.|http://www\.|http://).*?)\s%si', UpdateDB, $HTML); function UpdateDB($add){ $id = md5($add); mysql_query("INSERT INTO url_list (ID, URL) values ('".$id."', '".$add."')"); return "<a href=\"http://links.krazypicks.com?url=".$id."\">KrazyPick Link</a> "; } echo $results; ?> Also in the DB, under the URL column, all it says is Array Quote Link to comment https://forums.phpfreaks.com/topic/128188-solved-need-help-string-replace/#findComment-664487 Share on other sites More sharing options...
Lamez Posted October 14, 2008 Author Share Posted October 14, 2008 Is this really a hard problem? I am not really sure on how to solve any of this. Quote Link to comment https://forums.phpfreaks.com/topic/128188-solved-need-help-string-replace/#findComment-664602 Share on other sites More sharing options...
darkfreaks Posted October 14, 2008 Share Posted October 14, 2008 have you tried hashing it instead of md5 hashing ??? <?php //DB Connection $HTML = $_POST['html']; $results = preg_replace_callback('%\b((?:www\.|http://www\.|http://).*?)\s%si', UpdateDB, $HTML); function UpdateDB($add){ $id = hash($add); mysql_query("INSERT INTO url_list (ID, URL) values ('".$id."', '".$add."')"); return "<a href=\"http://links.krazypicks.com?url=".$id."\">KrazyPick Link</a> "; } echo $results; ?> Quote Link to comment https://forums.phpfreaks.com/topic/128188-solved-need-help-string-replace/#findComment-664731 Share on other sites More sharing options...
Lamez Posted October 14, 2008 Author Share Posted October 14, 2008 let me give it a go real quick! Quote Link to comment https://forums.phpfreaks.com/topic/128188-solved-need-help-string-replace/#findComment-664738 Share on other sites More sharing options...
Lamez Posted October 14, 2008 Author Share Posted October 14, 2008 nope, I get this error now Warning: hash() expects at least 2 parameters, 1 given in /mounted-storage/home48c/sub007/sc33591-LWQU/link_check/html_test.php on line 11 KrazyPick Link Quote Link to comment https://forums.phpfreaks.com/topic/128188-solved-need-help-string-replace/#findComment-664739 Share on other sites More sharing options...
Lamez Posted October 14, 2008 Author Share Posted October 14, 2008 Warning: md5() expects parameter 1 to be string, array given in /mounted-storage/home48c/sub007/sc33591-LWQU/link_check/html_test.php on line 11 KrazyPick Link ok so it is in an array, but how do I take it out and form a string? Quote Link to comment https://forums.phpfreaks.com/topic/128188-solved-need-help-string-replace/#findComment-664973 Share on other sites More sharing options...
MadTechie Posted October 14, 2008 Share Posted October 14, 2008 Yeah my bad you need to use $Add[1] instead of $Add <?php $HTML = "this is a test www.apple.com blar tesing http://apple.com blob http://www.apple.com hee "; $result = preg_replace_callback('%\b((?:www\.|http://www\.|http://).*?)\s%si', 'UpdateDB', $HTML); echo "<br>Final Output<br>"; echo $result; function UpdateDB($Add) { $id = md5($Add[1]); $url = $Add[1]; //Add the connection stuff for the database #mysql_query("INSERT INTO mytable (ID, URL) values ('$id','$url')"); //debug echo "INSERT INTO mytable (ID, URL) values ('$id','$url')"."<br>\n"; return "<a href=\"linkcheck.php?ID=$id\">LINK</a>"; } ?> INSERT INTO mytable (ID, URL) values ('e845cbdc3785b1a67978cbc5a146a168','www.apple.com')<br> INSERT INTO mytable (ID, URL) values ('0f82f8155826020d153245b61160ed4e','http://apple.com')<br> INSERT INTO mytable (ID, URL) values ('e9ea2574c49c3778f166e8b4b6ed63dd','http://www.apple.com')<br> <br>Final Output<br>this is a test <a href="linkcheck.php?ID=e845cbdc3785b1a67978cbc5a146a168">LINK</a>blar tesing <a href="linkcheck.php?ID=0f82f8155826020d153245b61160ed4e">LINK</a> blob <a href="linkcheck.php?ID=e9ea2574c49c3778f166e8b4b6ed63dd">LINK</a>hee *tested Quote Link to comment https://forums.phpfreaks.com/topic/128188-solved-need-help-string-replace/#findComment-665063 Share on other sites More sharing options...
Lamez Posted October 14, 2008 Author Share Posted October 14, 2008 Well I did use that bit of code, but nothing is inserted into the database, and I did add the connection, and changed the table name. Quote Link to comment https://forums.phpfreaks.com/topic/128188-solved-need-help-string-replace/#findComment-665191 Share on other sites More sharing options...
MadTechie Posted October 14, 2008 Share Posted October 14, 2008 can you post the code you have .. also add some debugging $query = "INSERT INTO mytable (ID, URL) values ('$id','$url')"; mysql_query($query) or die(mysql_error()."<br>$query"); Quote Link to comment https://forums.phpfreaks.com/topic/128188-solved-need-help-string-replace/#findComment-665200 Share on other sites More sharing options...
Lamez Posted October 14, 2008 Author Share Posted October 14, 2008 omg, I forgot to add the mysql_query, I have no idea why I forgot that. I am having a bit of trouble finding the link in the blob of text. say I put in www.phpfreaks.com it does not pick it up at all, I have to have text before, and after the link. here is the current code: <?php $HTML = $_POST['html']; $result = preg_replace_callback('%\b((?:www\.|http://www\.|http://).*?)\s%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_log` WHERE `url`='".$url."'"); if (!mysql_num_rows($sql) >= 1){ mysql_query("INSERT INTO url_list (ID, URL) values ('$id','$url')"); } return "<a href=\"http://links.krazypicks.com?url=$id\">KP Link</a> "; } ?> test: http://links.krazypicks.com/test.php Quote Link to comment https://forums.phpfreaks.com/topic/128188-solved-need-help-string-replace/#findComment-665219 Share on other sites More sharing options...
MadTechie Posted October 14, 2008 Share Posted October 14, 2008 test site seams fine! Ahhh i found a slight bug ~Slight update~ $result = preg_replace_callback('%\b((?:www\.|http://www\.|http://).*?)\s?%si', 'UpdateDB', $HTM Quote Link to comment https://forums.phpfreaks.com/topic/128188-solved-need-help-string-replace/#findComment-665225 Share on other sites More sharing options...
Lamez Posted October 14, 2008 Author Share Posted October 14, 2008 So I used the fix, now in the DB it inserts www., and also out puts phpfreaks.com, why? I am not sure on any of this, or else I would fix it on my own. code: <?php $HTML = $_POST['html']; $result = preg_replace_callback('%\b((?:www\.|http://www\.|http://).*?)\s?%si', 'UpdateDB', $HTML); echo "<br>Final Output<br>"; echo $result; 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/128188-solved-need-help-string-replace/#findComment-665230 Share on other sites More sharing options...
MadTechie Posted October 14, 2008 Share Posted October 14, 2008 scrap that.. use this $result = preg_replace_callback('%\b((?:www\.|http://www\.|http://).*)\b%si', 'UpdateDB', $HTML); Quote Link to comment https://forums.phpfreaks.com/topic/128188-solved-need-help-string-replace/#findComment-665234 Share on other sites More sharing options...
Lamez Posted October 14, 2008 Author Share Posted October 14, 2008 man you are truly a php god! Quote Link to comment https://forums.phpfreaks.com/topic/128188-solved-need-help-string-replace/#findComment-665246 Share on other sites More sharing options...
Lamez Posted October 14, 2008 Author Share Posted October 14, 2008 TYVM Quote Link to comment https://forums.phpfreaks.com/topic/128188-solved-need-help-string-replace/#findComment-665247 Share on other sites More sharing options...
MadTechie Posted October 14, 2008 Share Posted October 14, 2008 man you are truly a php god! LOL thanx Quote Link to comment https://forums.phpfreaks.com/topic/128188-solved-need-help-string-replace/#findComment-665253 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.