PHP - Youtube Url Extraction Help!!
hello,
I am trying to figure out how I can take only the v= in the youtube urls http://www.youtube.com/watch?v=nGawAhRjtoA&feature=topvideos i just want php to take v=nGawAhRjtoA and ignore everything else any ideas guys/gals? thanks Similar TutorialsHey, I have a script that is meant to grab links of a specific type. Code: [Select] <?php //need to some how extract all links from this text $link = '[quote]http://www.domain.com/?d=03WO6WPC random text, http://www.domain.com/?d=0334fWPChttp://www.domain.com/?d=03WV4SPC[/quote]'; ?> The urls are always the same character length, but there is no telling how the user types them out so im looking for a way to extract the 3 urls based on domain.com. The end result should be to create an array of 3 urls which belong to domain.com . I tried explode but some one may type it without spaces so explode fails.. any ideas? OK, I just want to extract the agency name, complete address, and phone number from this mess : {"facilities": [ { "fclt_name":"BEACH & O'NEILL IN", "fclt_addr":"7520 GREENBACK LN", "fclt_city":"CITRUS HEIGHTS", "fclt_state":"CA", "fclt_zip":"95610", "tel_no":"916.676.0844", "fax_no":"916.676.0860", "fclt_url":"null", "fclt_lattd":"38.6781788", "fclt_longtd":"-121.289615", "fclt_ctgy_cd":"2", "fclt_distance":"3.26341268894218446122718887944106659512" }, { "fclt_name":"AMERICAN AIM AUTO", "fclt_addr":"5341 SAN JUAN AVE", "fclt_city":"FAIR OAKS", "fclt_state":"CA", "fclt_zip":"95628", "tel_no":"916.962.0401", "fax_no":"916.962.0414", "fclt_url":"null", "fclt_lattd":"38.6625015", "fclt_longtd":"-121.2922782", "fclt_ctgy_cd":"2", "fclt_distance":"3.50675708898608342216618250068171298694" }, { "fclt_name":"INSZONE INSURANCE", "fclt_addr":"7200 FAIR OAKS BLVD STE 210", "fclt_city":"CARMICHAEL", "fclt_state":"CA", "fclt_zip":"95608", "tel_no":"916.503.8784", "fax_no":"916.486.4335", "fclt_url":"null", "fclt_lattd":"38.631717", "fclt_longtd":"-121.327626", "fclt_ctgy_cd":"2", "fclt_distance":"4.01207784800582596431030369642981690151" }, { "fclt_name":"PARK FAMILY INS &", "fclt_addr":"801 RIVERSIDE AVE STE 100", "fclt_city":"ROSEVILLE", "fclt_state":"CA", "fclt_zip":"95678", "tel_no":"888.723.7275", "fax_no":"866.772.2912", "fclt_url":"null", "fclt_lattd":"38.732289", "fclt_longtd":"-121.289295", "fclt_ctgy_cd":"2", "fclt_distance":"4.47210016333570016664044149856001806252" }, { "fclt_name":"RK JACOBS INSURANC", "fclt_addr":"4777 SUNRISE BLVD STE B", "fclt_city":"FAIR OAKS", "fclt_state":"CA", "fclt_zip":"95628", "tel_no":"916.966.3733", "fax_no":"916.966.0177", "fclt_url":"null", "fclt_lattd":"38.6525671", "fclt_longtd":"-121.2728244", "fclt_ctgy_cd":"2", "fclt_distance":"4.75887214653382230652493164121477832758" }, { "fclt_name":"BERTOLINO INSURANC", "fclt_addr":"2985 FULTON AVE", "fclt_city":"SACRAMENTO", "fclt_state":"CA", "fclt_zip":"95821", "tel_no":"916.384.9621", "fax_no":"877.553.0066", "fclt_url":"null", "fclt_lattd":"38.6190831", "fclt_longtd":"-121.4015452", "fclt_ctgy_cd":"2", "fclt_distance":"5.50381610176691043722708919483708216851" }, { "fclt_name":"THE PEXA GROUP", "fclt_addr":"1221 PLEASANT GROVE BLVD", "fclt_city":"ROSEVILLE", "fclt_state":"CA", "fclt_zip":"95678", "tel_no":"916.788.4200", "fax_no":"916.788.4204", "fclt_url":"null", "fclt_lattd":"38.772237", "fclt_longtd":"-121.308503", "fclt_ctgy_cd":"2", "fclt_distance":"6.25871993199859278950600593840623920844" }, { "fclt_name":"PARAMOUNT EQUITY I", "fclt_addr":"8781 SIERRA COLLEGE BLVD", "fclt_city":"ROSEVILLE", "fclt_state":"CA", "fclt_zip":"95661", "tel_no":"877.284.2424", "fax_no":"888.811.2910", "fclt_url":"null", "fclt_lattd":"38.7424319", "fclt_longtd":"-121.2511908", "fclt_ctgy_cd":"2", "fclt_distance":"6.50250135161509994547872070619122902873" }, { "fclt_name":"PETERSON & GRANTHA", "fclt_addr":"1508 EUREKA RD STE 175", "fclt_city":"ROSEVILLE", "fclt_state":"CA", "fclt_zip":"95661", "tel_no":"916.431.0400", "fax_no":"916.431.0221", "fclt_url":"null", "fclt_lattd":"38.749593", "fclt_longtd":"-121.250556", "fclt_ctgy_cd":"2", "fclt_distance":"6.83036958706746253088617532680453999753" }, { "fclt_name":"INDEPENDENT SOL UN", "fclt_addr":"2723 ZINFANDEL DR", "fclt_city":"RANCHO CORDOVA", "fclt_state":"CA", "fclt_zip":"95670", "tel_no":"916.635.6760", "fax_no":"916.635.9804", "fclt_url":"null", "fclt_lattd":"38.5967846", "fclt_longtd":"-121.2894781", "fclt_ctgy_cd":"2", "fclt_distance":"7.03267554456276560054938083160853750814" }, { "fclt_name":"MORE CHOICES INS A", "fclt_addr":"1474 STONE POINT DR # 131", "fclt_city":"ROSEVILLE", "fclt_state":"CA", "fclt_zip":"95661", "tel_no":"916.899.6600", "fax_no":"916.647.0522", "fclt_url":"null", "fclt_lattd":"38.755322", "fclt_longtd":"-121.249216", "fclt_ctgy_cd":"2", "fclt_distance":"7.14043819089449986827741629585808532375" }, { "fclt_name":"ALBANO DALE DUNN &", "fclt_addr":"9197 GREENBACK LN", "fclt_city":"ORANGEVALE", "fclt_state":"CA", "fclt_zip":"95662", "tel_no":"916.988.0214", "fax_no":"916.989.4719", "fclt_url":"null", "fclt_lattd":"38.678737", "fclt_longtd":"-121.212147", "fclt_ctgy_cd":"2", "fclt_distance":"7.40385556560869808878938590652772224486" }, { "fclt_name":"MCGEE & THIELEN IN", "fclt_addr":"3780 ROSIN CT STE 120", "fclt_city":"SACRAMENTO", "fclt_state":"CA", "fclt_zip":"95834", "tel_no":"916.646.1919", "fax_no":"916.646.0995", "fclt_url":"null", "fclt_lattd":"38.636195", "fclt_longtd":"-121.473132", "fclt_ctgy_cd":"2", "fclt_distance":"7.57412262483417036891911065525086823482" }, { "fclt_name":"AGENTS RESOURCES I", "fclt_addr":"11190 SUN CENTER DR", "fclt_city":"RANCHO CORDOVA", "fclt_state":"CA", "fclt_zip":"95670", "tel_no":"916.443.4221", "fax_no":"916.443.5559", "fclt_url":"null", "fclt_lattd":"38.597237", "fclt_longtd":"-121.267659", "fclt_ctgy_cd":"2", "fclt_distance":"7.61684981655654181229982085243856553867" }, { "fclt_name":"STEVE C LUTH INS", "fclt_addr":"9480 MADISON AVE STE 1", "fclt_city":"ORANGEVALE", "fclt_state":"CA", "fclt_zip":"95662", "tel_no":"888.597.8383", "fax_no":"916.989.9102", "fclt_url":"null", "fclt_lattd":"38.6735726", "fclt_longtd":"-121.2007054", "fclt_ctgy_cd":"2", "fclt_distance":"8.053760009460164598304836725423812559" }, { "fclt_name":"MCDOWALL & KEENEY", "fclt_addr":"865 HOWE AVE STE 200", "fclt_city":"SACRAMENTO", "fclt_state":"CA", "fclt_zip":"95825", "tel_no":"916.567.3233", "fax_no":"916.567.3155", "fclt_url":"null", "fclt_lattd":"38.581372", "fclt_longtd":"-121.41588", "fclt_ctgy_cd":"2", "fclt_distance":"8.16424077949136484737583499892043887019" }, { "fclt_name":"SIERRA OAK INS SER", "fclt_addr":"9700 BUSINESS PARK DR STE 105", "fclt_city":"SACRAMENTO", "fclt_state":"CA", "fclt_zip":"95827", "tel_no":"916.364.7380", "fax_no":"916.364.7381", "fclt_url":"null", "fclt_lattd":"38.568104", "fclt_longtd":"-121.334623", "fclt_ctgy_cd":"2", "fclt_distance":"8.27507991633456734395325050580063137134" }, { "fclt_name":"RICHARD CHRISTOPHE", "fclt_addr":"5842 LONETREE BLVD", "fclt_city":"ROCKLIN", "fclt_state":"CA", "fclt_zip":"95765", "tel_no":"916.626.3305", "fax_no":"916.471.0311", "fclt_url":"null", "fclt_lattd":"38.8065456", "fclt_longtd":"-121.293125", "fclt_ctgy_cd":"2", "fclt_distance":"8.76951297025304552186130788422901665504" }, { "fclt_name":"ADEPT INSURANCE SE", "fclt_addr":"101 PARKSHORE DR STE 30061", "fclt_city":"FOLSOM", "fclt_state":"CA", "fclt_zip":"95630", "tel_no":"916.944.2192", "fax_no":"866.529.5303", "fclt_url":"null", "fclt_lattd":"38.6570589", "fclt_longtd":"-121.186783", "fclt_ctgy_cd":"2", "fclt_distance":"8.9960609261835699863946424309422450653" }, { "fclt_name":"PARAGON INSURANCE", "fclt_addr":"301 NATOMA ST STE 104", "fclt_city":"FOLSOM", "fclt_state":"CA", "fclt_zip":"95630", "tel_no":"916.353.1023", "fax_no":"916.353.1370", "fclt_url":"null", "fclt_lattd":"38.678047", "fclt_longtd":"-121.168827", "fclt_ctgy_cd":"2", "fclt_distance":"9.73781780936977222523189878525699239046" }, { "fclt_name":"CLINTON POLLEY GRO", "fclt_addr":"1675 CREEKSIDE DR STE 100", "fclt_city":"FOLSOM", "fclt_state":"CA", "fclt_zip":"95630", "tel_no":"916.984.3000", "fax_no":"916.984.3100", "fclt_url":"null", "fclt_lattd":"38.6716438", "fclt_longtd":"-121.1446657", "fclt_ctgy_cd":"2", "fclt_distance":"11.07358533782419719432038848742812184727" }, { "fclt_name":"ALPHA BOND INSURAN", "fclt_addr":"3918 60TH ST", "fclt_city":"SACRAMENTO", "fclt_state":"CA", "fclt_zip":"95820", "tel_no":"866.313.3077", "fax_no":"916.429.7974", "fclt_url":"null", "fclt_lattd":"38.5393731", "fclt_longtd":"-121.4344591", "fclt_ctgy_cd":"2", "fclt_distance":"11.21762941497442801416098309046154379963" }, { "fclt_name":"HEBARD INSURANCE A", "fclt_addr":"3837 TAYLOR RD", "fclt_city":"LOOMIS", "fclt_state":"CA", "fclt_zip":"95650", "tel_no":"916.652.0404", "fax_no":"916.652.9123", "fclt_url":"null", "fclt_lattd":"38.81657", "fclt_longtd":"-121.197889", "fclt_ctgy_cd":"2", "fclt_distance":"12.08374482196660408349940289432841322946" }, { "fclt_name":"PILCHER INSURANCE", "fclt_addr":"3805 TAYLOR RD STE 1", "fclt_city":"LOOMIS", "fclt_state":"CA", "fclt_zip":"95650", "tel_no":"916.660.1670", "fax_no":"916.660.1672", "fclt_url":"null", "fclt_lattd":"38.817032", "fclt_longtd":"-121.197206", "fclt_ctgy_cd":"2", "fclt_distance":"12.13211505726556203701939114285606195057" }, { "fclt_name":"RUSSELL VANG INS &", "fclt_addr":"2751 FRUITRIDGE RD STE 15", "fclt_city":"SACRAMENTO", "fclt_state":"CA", "fclt_zip":"95824", "tel_no":"916.428.2267", "fax_no":"916.428.2341", "fclt_url":"null", "fclt_lattd":"38.517011", "fclt_longtd":"-121.4513314", "fclt_ctgy_cd":"2", "fclt_distance":"13.00258097375703227426814846084345607012" }, { "fclt_name":"PC INSURANCE AGENC", "fclt_addr":"6333 STOCKTON BLVD STE A", "fclt_city":"SACRAMENTO", "fclt_state":"CA", "fclt_zip":"95824", "tel_no":"916.391.5990", "fax_no":"916.391.5993", "fclt_url":"null", "fclt_lattd":"38.5111875", "fclt_longtd":"-121.4360945", "fclt_ctgy_cd":"2", "fclt_distance":"13.04926930736758364287316544823571444809" }, { "fclt_name":"GOLDENBEST INSURAN", "fclt_addr":"6830 STOCKTON BLVD # 100", "fclt_city":"SACRAMENTO", "fclt_state":"CA", "fclt_zip":"95823", "tel_no":"916.231.9955", "fax_no":"916.231.9954", "fclt_url":"null", "fclt_lattd":"38.502632", "fclt_longtd":"-121.43303", "fclt_ctgy_cd":"2", "fclt_distance":"13.54608070539524090996150854589636455506" }, { "fclt_name":"EDWARD C BRODIE IN", "fclt_addr":"2379 GATEWAY OAKS DR STE 150", "fclt_city":"SACRAMENTO", "fclt_state":"CA", "fclt_zip":"95822", "tel_no":"916.927.6343", "fax_no":"916.927.8848", "fclt_url":"null", "fclt_lattd":"38.5128714", "fclt_longtd":"-121.4970294", "fclt_ctgy_cd":"2", "fclt_distance":"14.46565232261373440674810015002201060961" }, { "fclt_name":"LINH DO INSURANCE", "fclt_addr":"6511 SAVINGS PL STE 115", "fclt_city":"SACRAMENTO", "fclt_state":"CA", "fclt_zip":"95828", "tel_no":"916.393.8383", "fax_no":"916.393.8382", "fclt_url":"null", "fclt_lattd":"38.4739858", "fclt_longtd":"-121.3884671", "fclt_ctgy_cd":"2", "fclt_distance":"14.89569563450147516294105371450235166475" }, { "fclt_name":"STRATTON AGENCY", "fclt_addr":"957 INDUSTRIAL RD STE C", "fclt_city":"SAN CARLOS", "fclt_state":"CA", "fclt_zip":"95762", "tel_no":"650.508.0124", "fax_no":"650.508.0121", "fclt_url":"null", "fclt_lattd":"38.6637192", "fclt_longtd":"-121.067907", "fclt_ctgy_cd":"2", "fclt_distance":"15.24924065635783489201051962237991277729" }, { "fclt_name":"PACIFIC INTERSTATE", "fclt_addr":"5072 HILLSDALE CIR STE 110", "fclt_city":"EL DORADO HILLS", "fclt_state":"CA", "fclt_zip":"95762", "tel_no":"916.941.0518", "fax_no":"916.941.0547", "fclt_url":"null", "fclt_lattd":"38.621938", "fclt_longtd":"-121.062804", "fclt_ctgy_cd":"2", "fclt_distance":"16.0891004210135393693458563137933030129" }, { "fclt_name":"AMAZING INSURANCE", "fclt_addr":"8398 LAPORTE WAY", "fclt_city":"ELK GROVE", "fclt_state":"CA", "fclt_zip":"95624", "tel_no":"916.719.6449", "fax_no":"916.258.6679", "fclt_url":"null", "fclt_lattd":"38.445406", "fclt_longtd":"-121.394576", "fclt_ctgy_cd":"2", "fclt_distance":"16.89751994304863412037777682922840849653" }, { "fclt_name":"WAHLA INSURANCE &", "fclt_addr":"4809 LAGUNA BLVD STE 100", "fclt_city":"ELK GROVE", "fclt_state":"CA", "fclt_zip":"95758", "tel_no":"916.429.4741", "fax_no":"916.429.4743", "fclt_url":"null", "fclt_lattd":"38.424506", "fclt_longtd":"-121.449703", "fclt_ctgy_cd":"2", "fclt_distance":"18.95918985420010413223068782438653209117" }, { "fclt_name":"MOTHER LODE INS SE", "fclt_addr":"2514 CAMEO DR STE A", "fclt_city":"CAMERON PARK", "fclt_state":"CA", "fclt_zip":"95682", "tel_no":"530.677.8755", "fax_no":"530.677.8314", "fclt_url":"null", "fclt_lattd":"38.6578609", "fclt_longtd":"-120.999481", "fclt_ctgy_cd":"2", "fclt_distance":"18.96331840626573060295348092634463597585" }, { "fclt_name":"WOODEL INSURANCE", "fclt_addr":"8788 ELK GROVE BLVD STE P", "fclt_city":"ELK GROVE", "fclt_state":"CA", "fclt_zip":"95624", "tel_no":"916.714.5122", "fax_no":"916.714.5123", "fclt_url":"null", "fclt_lattd":"38.408374", "fclt_longtd":"-121.377051", "fclt_ctgy_cd":"2", "fclt_distance":"19.33537262024884176605153693999802777133" }, { "fclt_name":"AMAN INSURANCE AGE", "fclt_addr":"8788 ELK GROVE BLVD BLDG 3", "fclt_city":"ELK GROVE", "fclt_state":"CA", "fclt_zip":"95624", "tel_no":"916.213.1900", "fax_no":"800.714.6082", "fclt_url":"null", "fclt_lattd":"38.408374", "fclt_longtd":"-121.377051", "fclt_ctgy_cd":"2", "fclt_distance":"19.33537262024884176605153693999802777133" }, { "fclt_name":"MULHOLLAND INSURAN", "fclt_addr":"2358 MARITIME DR STE 100", "fclt_city":"ELK GROVE", "fclt_state":"CA", "fclt_zip":"95758", "tel_no":"916.691.5555", "fax_no":"916.691.0555", "fclt_url":"null", "fclt_lattd":"38.413727", "fclt_longtd":"-121.483123", "fclt_ctgy_cd":"2", "fclt_distance":"20.24810658073937047943171540052851815376" }, { "fclt_name":"SILLECT INSURANCE", "fclt_addr":"100 KENTUCKY AVE", "fclt_city":"WOODLAND", "fclt_state":"CA", "fclt_zip":"95695", "tel_no":"530.662.9050", "fax_no":"888.613.5849", "fclt_url":"null", "fclt_lattd":"38.691387", "fclt_longtd":"-121.781223", "fclt_ctgy_cd":"2", "fclt_distance":"23.3148181263597264149496516029276053035" }, { "fclt_name":"VAUGHT WRIGHT & BO", "fclt_addr":"533 MAIN ST", "fclt_city":"PLACERVILLE", "fclt_state":"CA", "fclt_zip":"95667", "tel_no":"530.622.1835", "fax_no":"530.622.3860", "fclt_url":"null", "fclt_lattd":"38.7298", "fclt_longtd":"-120.798354", "fclt_ctgy_cd":"2", "fclt_distance":"29.83338181060752344743347837235784856168" }, { "fclt_name":"DARR INSURANCE AGE", "fclt_addr":"550 MAIN ST", "fclt_city":"PLACERVILLE", "fclt_state":"CA", "fclt_zip":"95667", "tel_no":"530.217.6002", "fax_no":"530.626.4590", "fclt_url":"null", "fclt_lattd":"38.728995", "fclt_longtd":"-120.797821", "fclt_ctgy_cd":"2", "fclt_distance":"29.85673424682092359769083672633797070566" } ] } I currently have an array called: $find[pagetext] In this array, there is going to be one to several instances where I am looking for a specific forum coding called: [url=http://megaupload.com/?d=X]http://megaupload.com/?d=X[/url] Everyone has used megaupload but what this script basically is going to do is check the validity of the upload site the user has chosen. Above I selected megaupload but there are about 6 sites I am going to check in the code I'm writing. I'm stuck on 1 part. How can I extract from $find[pagetext] all occurances of the website (In this case) megaupload and assign each instance to array. Once I assign it to an array I've already written a function that will check and see if the web link is valid I just need to basically extract each URL occurance of megaupload or whatever the upload site I am checking there is. All help is greatly appreciated. How could I from the varying URLs parse only the YouTube video ID? http://www.youtube.com/watch?v=SwrawcORlp0&feature=player_embedded http://www.youtube.com/watch?v=SwrawcORlp0&feature=popular How can I from the URLs above only extract the id into a variable $url SwrawcORlp0 Thanks, df This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=353645.0 I am in the process of teaching myself PHP/MySQL. I have taught myself other programming languages in the past so its not that i can't learn. but as i'm new and trying to learn both at the same time, i'm needing some help with php / mysql to datamine either of the following sites. www.findchips.com www.eciaauthorized.com WHat i want to do is after putting in the part number, for each distributor that returns data i want to extract the following data for each distributor Quantity Break Resale at quantity break Current Stock I want to write the data into a field in the database that holds the p/n's and my company's resale. I'm wanting to do this as an exercise so that i can dynamically benchmark my resales against that of my competitors. To get a feel of the data that is returned, please use the following p/n. 1n4001-e3/54 any and all help would be greatly appreciated Problem: I'm trying to build a junction table for a many to many relationship. Table A contains a title string that contains in it names that are stored in Table B. Both tables have nearly a million rows. Bad solution: The method I'm using right now is using PHP I fetch and store one table into an associative array. I then do a mysql_fetch loop on the second table and run this code to populate an array that is used to build the multi-insert SQL. $title = preg_replace ($names, $keys, $title); if (preg_match_all ('/(\d+)/', $title, $matches)) foreach ($matches[1] as $m) $inserts[$row['id'].'-'.$m] = 1; This works, but I'm looking for possibly a less cpu/memory intensive method. My remote server can't handle it, and we're talking hours and hours on a local server. It seems the bottleneck is with the preg_replace. I've also tried str_replace, which is only slightly faster. So, a method where I wouldn't have to pass around such large arrays, or an entirely different approach is what I'm looking for. Any ideas? Hi everyone, I do not know if this is the right place to ask the following, but I know all the php guru's read here. So please take a moment to read and please help point me in the right direction. I have a php website that I am developing, it is a job website, where my problem is that I need to be able to extract text from the following file formats: doc, docx, rtf, txt and maybe pdf. I have googled and done research on this subject, but I do not find any php scripts that can do the job properly. I have found a java app developed by apache that does the text extraction perfectly, called apache tika. (calling it using exec is really a problem, since most hosts don't provide root access.) I need a way to use this with php. If you know of any other method that I can do this, please help and suggest as this is a major bridge that I have to cross very urgently. your help will be much appreciated, thanks My db table has columns "id" (int-11), "date(varchar-50)", "author name(varchar-100)", "text (varchar-100000)"... I am storing images + text in text field of database. Everything is going fine while i am using ckeditor to insert data into the database for that particular text field. Now when i am retrieving data from database... i am able to extract id, date, autorname successfully (i have check it while the issue came)..but when i am trying to retrieve text field which have image, that jumps to page not found error... what could be the issue... am i having problem with database or editor that i am using???? hello, i want to extract the sender_id, sender_alias and text from the array that should be returned when requesting access to direct messages via API. I get the error "Fatal error: Call to undefined method TwitterOAuth::request() " referring to the line $direct_message = $OAuth->request('GET', $OAuth->url('https://api.twitter.com/1/direct_messages.json'), array('sender_id','screen_name' ,'text')); Code: [Select] // create new instance $OAuth = new TwitterOAuth($consumer_key,$consumer_secret, $oAuthToken, $oAuthSecret); $direct_message = $OAuth->request('GET', $OAuth->url('https://api.twitter.com/1/direct_messages.json'), array('sender_id','screen_name' ,'text')); $direct_message = json_decode($OAuth->response['response'], true); echo response; I have this function: function bbcode($input){ $input = strip_tags($input); $input = htmlentities($input); $search = array( '/\[b\](.*?)\[\/b\]/is', '/\[i\](.*?)\[\/i\]/is', '/\[u\](.*?)\[\/u\]/is', '/\[img\](.*?)\[\/img\]/is', '/\[url=http://(.*?)\](.*?)\[\/url\]/is', '/\[color=(.*?)\](.*?)\[\/color\]/is', '/\[yt\](.*?)\[\/yt\]/is', ); $replace = array( '<b>$1</b>', '<i>$1</i>', '<u>$1</u>', '<img src="$1" style="border:0">', '<a href="$1">$2</a>', '<font style="color:$1">$2</font>', '<object width="660" height="405"> <param name="movie" value="'.str_replace("watch?v=", "v/", $1).'" /> <param name="allowFullScreen" value="true" /> <param name="allowscriptaccess" value="always" /><embed type="application/x-shockwave-flash" width="660" height="405" src="'.str_replace("watch?v=", "v/", $1).'" allowscriptaccess="always" allowfullscreen="true"></embed> </object>', ); return nl2br(preg_replace($search,$replace,$input)); } There is an error on code: <param name="movie" value="'.str_replace("watch?v=", "v/", $1).'" /> and on: <param name="allowscriptaccess" value="always" /><embed type="application/x-shockwave-flash" width="660" height="405" src="'.str_replace("watch?v=", "v/", $1).'" allowscriptaccess="always" allowfullscreen="true"> How can i use str_replace in this situation ? :S Before you say about trying to use curl and fsockopen...I have tried those already but my host does not allow it due to their settings on their php.ini file. I am wondering if there is a way (other than those above) to grab the latest videos from a specific user on youtube, and be able to display them on a website, such as grabbing information about the video, as well as displaying it. If this is at all possible, and you can help...thanks in advance. Has anyone had any success doing this? I'm not sure if I should try to write this myself or use some kind of framework. I found the Zend Gdata framework (http://framework.zend.com/manual/en/zend.gdata.html) and tried it out but I kept getting error: Warning: include_once() [function.include]: Failed opening '1' for inclusion (include_path='.:/usr/share/pear') I'm assuming it needs to find PEAR which I don't have installed but no where in the Zend docs does it say that it requires PEAR so I'm a little confused. I've never used any of the Zend frameworks so I have no idea if it needs PEAR or not. Anyone have any other methods for doing this? thanks. Hi, I'm working with the YouTube API to echo a feed based on a user's query. My current code is below. With this code, a whole list of videos is retrieved. However, in order to present the feed as I wish to... I need to return each video in the feed individually. I am unsure how to do this and any advice would be really appreciated. Code: [Select] $feedURL = "http://gdata.youtube.com/feeds/api/videos/-/$youtubeQuery?orderby=viewCount&max-results=10"; // read feed into SimpleXML object $sxml = simplexml_load_file($feedURL); // iterate over entries in resultset // print each entry's details foreach ($sxml->entry as $entry) { // get nodes in media: namespace for media information $media = $entry->children('http://search.yahoo.com/mrss/'); // get video player URL $attrs = $media->group->player->attributes(); $watch = $attrs['url']; // get video thumbnail $attrs = $media->group->thumbnail[0]->attributes(); $thumbnail = $attrs['url']; // get <yt:duration> node for video length $yt = $media->children('http://gdata.youtube.com/schemas/2007'); $attrs = $yt->duration->attributes(); $length = $attrs['seconds']; // get video title $title = $media->group->title; // get <gd:rating> node for video ratings $gd = $entry->children('http://schemas.google.com/g/2005'); if ($gd->rating) { $attrs = $gd->rating->attributes(); $rating = $attrs['average']; } else { $rating = 0; } } ?> Code: [Select] $txt = preg_replace( "#\[yt\]http://www.youtube.com/watch?v=(.+?)\[/yt\]#is", '<embed src="http://www.youtube.com/v/\\1" type="application/x-shockwave-flash" wmode="transparent" width="512" height="313" allowfullscreen="true" />', $txt ); Okay this is my code just for inserting it into HTML, the problem is whenever I try to use: Code: [Select] [yt]http://www.youtube.com/watch?v=l1G7TJD6Xu0[/yt] On my form to enter it does not work? But if I use Code: [Select] $txt = preg_replace( "#\[yt\](.+?)\[/yt\]#is", '<embed src="http://www.youtube.com/v/\\1" type="application/x-shockwave-flash" wmode="transparent" width="512" height="313" allowfullscreen="true" />', $txt ); Code: [Select] [yt]l1G7TJD6Xu0[/yt] It works. But I want to use the full URL of the youtube, so I don't want my users to copy/paste just the "l1G7TJD6Xu0" Code , any help? Thank you Youtube has an advanced api to deliver xml; but when I try to parse its xml, it is not well-defined. I want to get "average rating" for a given video, but simple xml load disregard this section: $xml = simplexml_load_file('http://gdata.youtube.com/feeds/mobile/videos/wZ252E282go'); print_r($xml); How can I put the value of "average rating" into an string to echo? The application that I want to build is quite simple. Here is a bit of the background of the work flow: In my company, we create video for our client profile. After the video is done, we upload the video to our website and to youtube. It is done automatically. After a period of time, the client can delete the video. Of course, it will delete the video in our system as well as the video in youtube. For now, the video in our system is deleted automatically. However, youtube video is deleted manually. Our company has grown to have quite a lot of clients. It's hard for us to keep track clients that requested to delete their videos. We want to be able to have an application that will delete youtube video automatically. I already tried to play around with youtube authentication in http://code.google.com/apis/youtube/2.0/developers_guide_php.html#Authentication but I have no luck with the authentication. I want the application to be able to delete the video under my youtube account without having me to login to youtube. In my case right now, every time the application wants to delete the video, I have to send the request to youtube and ask for verification (i.e. I have to do application verification every time). Here is what I have done so far: ini_set('display_errors', 1); ini_set('log_errors', 1); ini_set('error_log', dirname(__FILE__) . '/error_log.txt'); error_reporting(E_ALL); require_once('db_class.php'); require_once 'Zend/Loader.php'; Zend_Loader::loadClass('Zend_Gdata_YouTube'); Zend_Loader::loadClass('Zend_Gdata_AuthSub'); Zend_Loader::loadClass('Zend_Gdata_App_Exception'); session_start(); setLogging('on'); $_SESSION['developerKey'] = 'AI39si5H3hL9tcKOMl80IqzoC6nb87ka1QLgHxLp9nFi1l44dLa987_Gi0rbofLePQdFEWf1lrSB8KGs4lXIrcF8TR6PhUcO3Q'; function getAuthSubRequestUrl() { $next = 'http://example.com/youtube_delete_video.php'; $scope = 'http://gdata.youtube.com'; $secure = false; $session = true; return Zend_Gdata_AuthSub::getAuthSubTokenUri($next, $scope, $secure, $session); } function updateAuthSubToken($singleUseToken) { try { $sessionToken = Zend_Gdata_AuthSub::getAuthSubSessionToken($singleUseToken); } catch (Zend_Gdata_App_Exception $e) { print 'ERROR - Token upgrade for ' . $singleUseToken . ' failed : ' . $e->getMessage(); return; } $_SESSION['sessionToken'] = $sessionToken; generateUrlInformation(); header('Location: ' . $_SESSION['homeUrl']); } function getAuthSubHttpClient() { try { $httpClient = Zend_Gdata_AuthSub::getHttpClient($_SESSION['sessionToken']); } catch (Zend_Gdata_App_Exception $e) { print 'ERROR - Could not obtain authenticated Http client object. ' . $e->getMessage(); return; } $httpClient->setHeaders('X-GData-Key', 'key='. $_SESSION['developerKey']); return $httpClient; } function generateUrlInformation() { if (!isset($_SESSION['operationsUrl']) || !isset($_SESSION['homeUrl'])) { $_SESSION['operationsUrl'] = 'http://'. $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']; $path = explode('/', $_SERVER['PHP_SELF']); $path[count($path)-1] = 'index.php'; $_SESSION['homeUrl'] = 'http://'. $_SERVER['HTTP_HOST'] . implode('/', $path); } } function loggingEnabled() { if ($_SESSION['logging'] == 'on') { return true; } } function setLogging($loggingOption, $maxLogItems = 10) { switch ($loggingOption) { case 'on' : $_SESSION['logging'] = 'on'; $_SESSION['log_currentCounter'] = 0; $_SESSION['log_maxLogEntries'] = $maxLogItems; break; case 'off': $_SESSION['logging'] = 'off'; break; } } function logMessage($message, $messageType) { if (!isset($_SESSION['log_maxLogEntries'])) { $_SESSION['log_maxLogEntries'] = 20; } if (!isset($_SESSION['log_currentCounter'])) { $_SESSION['log_currentCounter'] = 0; } $currentCounter = $_SESSION['log_currentCounter']; $currentCounter++; if ($currentCounter > $_SESSION['log_maxLogEntries']) { $_SESSION['log_currentCounter'] = 0; } $logLocation = 'log_entry_'. $currentCounter . '_' . $messageType; $_SESSION[$logLocation] = $message; $_SESSION['log_currentCounter'] = $currentCounter; } function printCacheWarning() { return '<p class="note">' . 'Please note that the change may not be reflected in the API ' . 'immediately due to caching.<br/>' . 'Please refer to the API documentation for more details.</p>'; } function editVideoData($videoId) { $httpClient = getAuthSubHttpClient(); $youTubeService = new Zend_Gdata_YouTube($httpClient); $videoEntryToUpdate = $youTubeService->getFullVideoEntry($videoId); if (!$videoEntryToUpdate instanceof Zend_Gdata_YouTube_VideoEntry) { print 'ERROR - Could not find a video entry with id ' . $videoId . '<br />' . printCacheWarning(); return; } try { $putUrl = $videoEntryToUpdate->getEditLink()->getHref(); } catch (Zend_Gdata_App_Exception $e) { print 'ERROR - Could not obtain video entry\'s edit link: ' . $e->getMessage() . '<br />'; return; } $videoEntryToUpdate->setVideoTitle("My Test Movie - Private 10000012"); $videoEntryToUpdate->setVideoDescription("My Test Movie - Private 10000012"); $videoEntryToUpdate->setVideoPrivate(); try { $updatedEntry = $youTubeService->updateEntry($videoEntryToUpdate, $putUrl); if (loggingEnabled()) { logMessage($httpClient->getLastRequest(), 'request'); logMessage($httpClient->getLastResponse()->getBody(), 'response'); } } catch (Zend_Gdata_App_HttpException $httpException) { print 'ERROR ' . $httpException->getMessage() . ' HTTP details<br /><textarea cols="100" rows="20">' . $httpException->getRawResponseBody() . '</textarea><br />' . '<a href="session_details.php">' . 'click here to view details of last request</a><br />'; return; } catch (Zend_Gdata_App_Exception $e) { print 'ERROR - Could not post video meta-data: ' . $e->getMessage(); return; } print 'Entry updated successfully.<br /><a href="#" onclick="' . 'ytVideoApp.presentFeed(\'search_owner\', 5, 0, \'none\'); ' . 'ytVideoApp.refreshSearchResults();" >' . '(refresh your video listing)</a><br />' . printCacheWarning(); } if (!isset($_GET['token'])) { $returnURL = getAuthSubRequestUrl(); echo "<a href=".$returnURL.">Link To Google</a>"; } else { $singleUseToken = $_GET['token']; updateAuthSubToken($singleUseToken); /* editVideoData('mJDRXXaFVGw'); */ } This is how I call the function: http://example.com/youtube_delete_video.php So, what I need basically is to know 1. how can I store the authentication after I verify it from youtube? 2. What function to populate after I store the authentication? <- I couldn't figure where this part is in the documentation. PS: example.com is not a real url. It's just for the sake of writing the post he ) Does anyone know of a json or php method of authenticating a youtube user without using zend? Code: [Select] <?php $id = NULL; $username = 'myYouTubeAccount'; $url = 'http://gdata.youtube.com/feeds/api/users/%s/uploads?orderby=updated&max-results=8'; $xml = simplexml_load_file(sprintf($url, $username)); foreach ($xml->entry as $entry) : $kids = $entry->children('http://search.yahoo.com/mrss/'); $attributes = $kids->group->content[0]->attributes(); $flv = $attributes['url']; $attributes = $kids->group->player->attributes(); $link = $attributes['url']; $querystring = parse_url($link,PHP_URL_QUERY); parse_str($querystring, $id_temp); $id = $id_temp['v']; ?> <a href="<?=$link?>"> <img src="http://i4.ytimg.com/vi/<?=$id?>/default.jpg" /> </a> <?php endforeach; ?> Basically what the title says, I want to detect a upload and post a notification, how would i do this? |