QuickOldCar
Staff Alumni-
Posts
2,972 -
Joined
-
Last visited
-
Days Won
28
Everything posted by QuickOldCar
-
extract youtube.com variables from a comment
QuickOldCar replied to fluxadd's topic in PHP Coding Help
Take a look at this post http://www.phpfreaks.com/forums/index.php?topic=342974.msg1619535#msg1619535 -
maybe try this in there for the text first $text = str_ireplace("http://", " http://", $text); I did write something different that discovered non hyperlinks and made them hyperlinks, I say this because I did it in a different way. <?php function parseHOST($url){ $url = str_ireplace("www.",'',trim($url)); $parsedUrl = @parse_url($url); return strtolower(trim($parsedUrl['host'] ? $parsedUrl['host'] : array_shift(explode('/', $parsedUrl['path'], 2)))); } function removeSPAM($text){ $spam_array = array("spam-site.com","spam.com"); $text = preg_replace( "/(www\.)/is", "http://", $text); $text = str_replace(array("http://http://","http://https://"), "http://", $text); $reg_exUrl = "/(http|https|ftp|ftps|)\:\/\/[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(\/\S*)?/"; preg_match_all($reg_exUrl, $text, $matches); $usedPatterns = array(); foreach($matches[0] as $pattern){ if(!array_key_exists($pattern, $usedPatterns)){ $usedPatterns[$pattern]=true; } if(in_array(parseHOST($pattern),$spam_array)){ $text = str_ireplace($pattern, " ", $text); } } return $text; } $text = "Visit my youtube link</a> Some sample text with WWW.AOL.com. <br /> testinghttp://spam.com/more-spam <br />http://www.youtube.com/watch?v=csgZ2b1bW2o and a spam link is http://www.spam-site.com/click here for spam<br />Anyone use www.myspace.com? <br />Some people are nuts, look at this stargate link at http://www.youtube.com/watch?v=ZKoUm6z5SzU&feature=grec_index , like aliens exist or something. http://www.youtube.com/watch?v=sfN-7HczmOU&feature=grec_index and here's a secure site https://familyhistory.hhs.gov, unless you use curl or allow secure connections it will never get a title. <br /> This is a not valid site http://zzzzzzz and this is a dead site http://zwzwzwxzw.com.<br /> Lastly lets try an already made hyperlink and see what it does <a href='http://dynaindex.com'>dynaindex.com</a>"; echo removeSPAM($text); ?>
-
ahh, i see what you mean, yeah totally different. Are you going to be checking from a list of possible spammy domains? I would think it would be nearly impossible to detect any type of domain name within a paragraph. Try something like this. <?php function parseHOST($url){ $url = str_ireplace("www.",'',trim($url)); $parsedUrl = @parse_url($url); return strtolower(trim($parsedUrl['host'] ? $parsedUrl['host'] : array_shift(explode('/', $parsedUrl['path'], 2)))); } //your text input from a post $text = "Visit my youtube link</a> Some sample text with WWW.AOL.com. <br /> http://spam.com/more-spam <br />http://www.youtube.com/watch?v=csgZ2b1bW2o and a spam link is http://www.spam-site.com/click here for spam<br />Anyone use www.myspace.com? <br />Some people are nuts, look at this stargate link at http://www.youtube.com/watch?v=ZKoUm6z5SzU&feature=grec_index , like aliens exist or something. http://www.youtube.com/watch?v=sfN-7HczmOU&feature=grec_index and here's a secure site https://familyhistory.hhs.gov, unless you use curl or allow secure connections it will never get a title. <br /> This is a not valid site http://zzzzzzz and this is a dead site http://zwzwzwxzw.com.<br /> Lastly lets try an already made hyperlink and see what it does <a href='http://dynaindex.com'>dynaindex.com</a>"; $spam_array = array("spam-site.com","spam.com");//add to the list //space anything that would get included in a link, add the space $text = str_ireplace(array("<br />","\n","\r"),array(" <br /> "," \n "," \r "),$text); $text = str_replace(" ", " ", $text); //explode the text by spaces $text_explode = explode(" ",$text); //loop and return words not in spam array foreach($text_explode as $words){ if(!in_array(parseHOST($words),$spam_array)){ echo " $words "; } } ?>
-
http://php.net/manual/en/function.parse-url.php <?php function parseHOST($url){ $url = str_ireplace("www.",'',trim($url)); $parsedUrl = @parse_url($url); return strtolower(trim($parsedUrl['host'] ? $parsedUrl['host'] : array_shift(explode('/', $parsedUrl['path'], 2)))); } //example echo parseHOST('http://google.com')."<br />"; echo parseHOST('http://www.google.com')."<br />"; echo parseHOST('google.com')."<br />"; ?>
-
going by what you have there if ($homepage != "") { if (!preg_match("/http/i",$homepage)) { $homepage = "http://" . $homepage; } }
-
I redid this a lot, all you need to do is use the $text value as whatever your text value may be. <?php //your text input from a post $text = "First lets do a hyperlink: <a href='http://www.youtube.com/watch?v=YaxKiZfQcX8'>Visit my youtube link</a> Some sample text with WWW.AOL.com. <br /> Here's a shortened link - youtu.be/ZzDm2vMHabE <br />http://www.youtube.com/watch?v=csgZ2b1bW2o and a cool user page is http://www.youtube.com/user/cometodoyourwill<br />Anyone use www.myspace.com? <br />Some people are nuts, look at this stargate link at http://www.youtube.com/watch?v=ZKoUm6z5SzU&feature=grec_index , like aliens exist or something. http://www.youtube.com/watch?v=sfN-7HczmOU&feature=grec_index and here's a secure site https://familyhistory.hhs.gov, unless you use curl or allow secure connections it will never get a title. <br /> This is a not valid site http://zzzzzzz and this is a dead site http://zwzwzwxzw.com.<br /> Lastly lets try an already made hyperlink and see what it does <a href='http://dynaindex.com'>dynaindex.com</a>"; //space anything that would get included in a link, add the space $text = str_ireplace(array("<br />","\n","\r"),array(" <br /> "," \n "," \r "),$text); $text = str_replace(" ", " ", $text); //explode the text by spaces $text_explode = explode(" ",$text); //loop replacing youtube links with embed codes, if not youtube embed return text foreach($text_explode as $words){ if (preg_match('~(?:youtube\.com/(?:[^/]+/.+/|(?:v|e(?:mbed)?)/|.*[?&]v=)|youtu\.be/)([^"&?/ ]{11})~i', $words, $match)) { $vidid = $match[1];//the id $link = "http://youtu.be/$vidid";//short link to video //grab the title $visit_url = "http://gdata.youtube.com/feeds/api/videos/".$vidid; $doc = new DOMDocument; @$doc->load($visit_url); $link_title = $doc->getElementsByTagName("title")->item(0)->nodeValue; if($link_title == ""){ $link_title = "Click to watch video."; } //display a link echo "<h3><a href='$link' TARGET='_blank'>$link_title</a></h3>"; //embed the video echo "<div>"; echo "<object style='height: 390px; width: 640px'> <param name='movie' value='http://www.youtube.com/v/$vidid&fs=1'> <param name='allowFullScreen' value='true'> <param name='allowScriptAccess' value='always'> <embed src='http://www.youtube.com/v/$vidid&fs=1' type='application/x-shockwave-flash' allowfullscreen='true' allowScriptAccess='always' width='640' height='390'></object>"; echo "</div><br />"; } else { //keep the original words echo " $words "; } } ?> Here's the demo of this code. http://get.blogdns.com/test/embed-youtube2.php
-
How can I take user input and append it to a url?
QuickOldCar replied to cyberhost's topic in PHP Coding Help
http://www.phpfreaks.com/forums/index.php?topic=342974.msg1618361#msg1618361 -
slight modification to return the url and not embed the player if not a youtube video link. <?php //parse the host, no http:// returned function parseHOST($url){ $new_parse_url = str_ireplace(array("www.","mms://","rtsp://","http://","https://", "http://", "ftp://", "feed://"), "", trim($url)); $parsedUrl = @parse_url("http://$new_parse_url"); return strtolower(trim($parsedUrl['host'] ? $parsedUrl['host'] : array_shift(explode('/', $parsedUrl['path'], 2)))); } function embedYOUTUBE($url){ $parsed_url = parseHOST($url); if($parsed_url == "youtu.be" || $parsed_url == "youtube.com"){ //convert youtu.be shortened to normal if($parsed_url == "youtu.be"){ $vidid = end(explode("/",trim($url))); $url = "http://www.youtube.com/v/$vidid"; } //youtube media embed if(preg_match("/(youtube.com\/(watch?|v\/|v=))/i",$url)){ $url = str_ireplace(array("&autoplay=$vidid","?f=videos","?f=playlists","&app=youtube_gdata","&feature=related"),"",$url); $vidparser = parse_url($url); parse_str($vidparser[query], $query); $vidid = ($query['v']); if($vidid == ""){ $vidid = end(explode("/",$url)); } //clean parameters and get title $vidid = str_ireplace(array("&app=youtube_gdata","&autoplay=$vidid","&autoplay=1","&fs=1"),"",$vidid); $visit_url = "http://gdata.youtube.com/feeds/api/videos/".$vidid; $doc = new DOMDocument; @$doc->load($visit_url); $link_title = $doc->getElementsByTagName("title")->item(0)->nodeValue; if($link_title == ""){ $link_title = "Click to watch video."; } //show results on page echo "<div>"; echo "<h2><a href='$url' TARGET='_blank'>$link_title</a></h2>"; echo $vidid."<br />"; echo "<object style='height: 390px; width: 640px'> <param name='movie' value='http://www.youtube.com/v/$vidid&fs=1'> <param name='allowFullScreen' value='true'> <param name='allowScriptAccess' value='always'> <embed src='http://www.youtube.com/v/$vidid&fs=1' type='application/x-shockwave-flash' allowfullscreen='true' allowScriptAccess='always' width='640' height='390'></object>"; echo "</div>"; } else { return "<a href='$url'>$url</a>"; } } else { return "<a href='$url'>$url</a>"; } } //examples echo embedYOUTUBE("http://phpfreaks.com"); echo embedYOUTUBE("http://www.youtube.com/watch?v=EHtWe4_Fkok&feature=watch-now-button&wide=1"); echo embedYOUTUBE("http://www.youtube.com/CartooningGenius"); echo embedYOUTUBE("http://www.youtube.com/v/7JxfgId3XTs&fs=1"); echo embedYOUTUBE("http://youtu.be/jlgVLblVSu8"); echo embedYOUTUBE("http://www.youtube.com/watch?v=w5Beh6fEJVs&feature=topvideos_sports"); ?>
-
Here's an embed I made and seems to work all instances. <?php //parse the host, no http:// returned function parseHOST($url){ $new_parse_url = str_ireplace(array("www.","mms://","rtsp://","http://","https://", "http://", "ftp://", "feed://"), "", trim($url)); $parsedUrl = @parse_url("http://$new_parse_url"); return strtolower(trim($parsedUrl['host'] ? $parsedUrl['host'] : array_shift(explode('/', $parsedUrl['path'], 2)))); } function embedYOUTUBE($url){ $parsed_url = parseHOST($url); //convert youtu.be shortened to normal if($parsed_url == "youtu.be"){ $vidid = end(explode("/",trim($url))); $url = "http://www.youtube.com/v/$vidid"; } //youtube media embed if(preg_match("/(youtube.com\/(watch?|v\/|v=))/i",$url)){ $url = str_ireplace(array("&autoplay=$vidid","?f=videos","?f=playlists","&app=youtube_gdata","&feature=related"),"",$url); $vidparser = parse_url($url); parse_str($vidparser[query], $query); $vidid = ($query['v']); if($vidid == ""){ $vidid = end(explode("/",$url)); } //clean parameters and get title $vidid = str_ireplace(array("&app=youtube_gdata","&autoplay=$vidid","&autoplay=1","&fs=1"),"",$vidid); $visit_url = "http://gdata.youtube.com/feeds/api/videos/".$vidid; $doc = new DOMDocument; @$doc->load($visit_url); $link_title = $doc->getElementsByTagName("title")->item(0)->nodeValue; if($link_title == ""){ $link_title = "Click to watch video."; } //show results on page echo "<div>"; echo "<h2><a href='$url' TARGET='_blank'>$link_title</a></h2>"; echo $vidid."<br />"; echo "<object style='height: 390px; width: 640px'> <param name='movie' value='http://www.youtube.com/v/$vidid&fs=1'> <param name='allowFullScreen' value='true'> <param name='allowScriptAccess' value='always'> <embed src='http://www.youtube.com/v/$vidid&fs=1' type='application/x-shockwave-flash' allowfullscreen='true' allowScriptAccess='always' width='640' height='390'></object>"; echo "</div>"; } else { return $url; } } //examples echo embedYOUTUBE("http://www.youtube.com/watch?v=EHtWe4_Fkok&feature=watch-now-button&wide=1"); echo embedYOUTUBE("http://www.youtube.com/CartooningGenius"); echo embedYOUTUBE("http://www.youtube.com/v/7JxfgId3XTs&fs=1"); echo embedYOUTUBE("http://youtu.be/jlgVLblVSu8"); echo embedYOUTUBE("http://www.youtube.com/watch?v=w5Beh6fEJVs&feature=topvideos_sports"); ?>
-
Problem with DB Query Speed (no code just question)
QuickOldCar replied to idontknowphp's topic in MySQL Help
The most likely cause for this was that your query results were very large, took too much time to fetch them, try increasing your timeout in php.ini It would also help to increase the memory in php.ini, and also create an index on any where/and/or values for the select statements in your database. Posting the actual code can get you better help. -
Trouble getting my "naughty words" function to work
QuickOldCar replied to Jeffro's topic in PHP Coding Help
You have 2 spots in the second array where it's missing a quote. Making the second array to replace is the hard way to go about this. http://get.blogdns.com/dynaindex/Safe-Filter/ Here's my bad words safe filter with the code below to give you an alternate way. -
http://php.net/manual/en/function.pdf-new.php And the rest of the PDF functions are to the left. Here's an example way to do it in php. http://astahost.com/info.php/Create-Pdf-Php_t4972.html
-
Take a look here. http://www.phpfreaks.com/tutorial/basic-pagination Take particular attention of the mysql query using LIMIT $sql = "SELECT id, number FROM numbers LIMIT $offset, $rowsperpage"; mysql results offset begins at zero, and how many results from that point (where to start from / amount per page)
-
I would read and make sure your site is legal. http://lotteriescouncil.org.uk/public/gamblingact/law.shtml Bitcoins or not, it still requires and uses trading of cash with gambling.
-
I noticed it had an issue not displaying the lightbox type images in firefox. Visiting the image url. http://www.veecy.com/business-seeking-funding/listingimage/164-1Maverick_Home_Page.png Warning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/veecy/public_html/seek-funding-listing-details.php on line 21
-
Look over and test of ajax MYSQL editor?
QuickOldCar replied to gearsgod's topic in Beta Test Your Stuff!
mysql> SHOW VARIABLES LIKE "character\_set\_database"; -
What you want seems to me is to scrape yahoo results using your own keywords, then from their search results create more keywords. How is that a game exactly?...anyway... Well yahoo has an api for this and it costs money as well. http://developer.yahoo.com/search/boss/ So unless you used curl, a scraper, a proxy, and do it without them knowing, the api is your best bet. Google and Bing offer free api's. http://code.google.com/apis/customsearch/ They stopped their websearch api. http://msdn.microsoft.com/en-us/library/dd251056.aspx
-
Look over and test of ajax MYSQL editor?
QuickOldCar replied to gearsgod's topic in Beta Test Your Stuff!
Maybe you should discover what charset their database actually is, not everyone uses UTF-8. -
Look over and test of ajax MYSQL editor?
QuickOldCar replied to gearsgod's topic in Beta Test Your Stuff!
I think having the database first then the tables would be more friendly. Having a dropdown of all the available columns, and upon selection it sorts by that would be nice. Or how about when you click on the displayed columns name it just sorts it by that and forget the dropdown. Having the ASC,DESC order. Jump ahead pages. Overall it seems to work, but easy versus deluxe functions is hard to get used to when need to get to some specific data. I don't know why people would hate phpmyadmin, I feel it does the job well considering how complex mysql is. I realize you just want a simple way to edit data, and that's what it does. A wee bit more work on navigation and some checking it could be useful. -
@QuickOldCa; Why define a variable $title just to use it one time? Showing where it came from, maybe if wanted to modify it in some way first.
-
if($title != ""){ echo "<div>$title</div>"; }
-
you never close your foreach loop, title should be a variable...$title, need to associate the row value to a variable. What kind of control are you looking for, while can do the same as foreach.
-
http://php.net/manual/en/function.mysql-fetch-row.php <?php $con = mysql_connect("localhost","root",""); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("database", $con); $result = mysql_query("SELECT title FROM table1"); while($row = mysql_fetch_array($result)){ $title = $row['title']; echo "<div>".$title."</div>"; } mysql_close($con); ?>
-
Webmin is pretty good and open source. http://www.webmin.com/