jeet_0077 Posted February 4, 2008 Share Posted February 4, 2008 Hi have a strange situation. I have to parse a file which is having some javascript. http://www.stickam.com/viewCategorySchedule.do?category=show/css/en/category/show/schedule.css The above is the URL from which i have to parse the contents. basically this is to get the Feeds from the site. I have done for XML and HTML but this is something different. If u see the source code of the link u can see it is having something like <script>buildScheduleDiv('scottcam','♫ScottKam♫','http://static.stickam.com/media/image/converted/thumb/1747/9798/9/0d87768c-cfd4-11dc-87c9-b9d39bf5edbe.jpg','165312','Aphex Studio Sessions w/ SCOTTKAM','Updates on my Music','Mon, 04 Feb 2008 21:15:00 +0000','Mon, 04 Feb 2008 23:15:00 +0000');</script> <script>buildScheduleDiv('millsyfm','The Lee Mills Show','http://static.stickam.com/media/image/converted/thumb/1747/5197/7/ae54e146-bf71-11dc-a6b7-cbddd6b72ad7.jpg','123373','THE LEE MILLS SHOW','Todays Best Music Mix - Music from all over the globe','Mon, 04 Feb 2008 22:00:00 +0000','Tue, 05 Feb 2008 00:00:00 +0000');</script> <script>buildScheduleDiv('faderwaveradio','Faderwave Radio','http://static.stickam.com/media/image/converted/thumb/1740/4491/1/15425039-731f-11dc-861a-2135e338a83b.jpg','110851','DJ Denis/House ','DJ Denis has been interested in DJing ever since he started listening to electronic music about 4 years ago, shortly after he became interested in what it is to be a DJ. After playing for about 3 years now, DJ Denis has come to like all forms of house and trance, and even some breakbeats. His playing history goes back to a multitude of clubs in Delhi, and soon moving to Providence he will be looking to start playing in the clubs regularly there.<br><br>','Mon, 04 Feb 2008 22:00:00 +0000','Mon, 04 Feb 2008 23:00:00 +0000');</script> I need to parse the contents available between buildScheduleDiv() so that I can enter the data in the database. If someone have any idea how to do that please help. Currently I am using file_get_contents() to get the content but unable to parse. Thanks in advance... Quote Link to comment https://forums.phpfreaks.com/topic/89427-solved-please-help/ Share on other sites More sharing options...
sasa Posted February 4, 2008 Share Posted February 4, 2008 try <?php $a = file_get_contents('http://www.stickam.com/viewCategorySchedule.do?category=show/css/en/category/show/schedule.css'); preg_match_all('/buildScheduleDiv\(([^)]+)\)/', $a, $b); print_r($b); ?> Quote Link to comment https://forums.phpfreaks.com/topic/89427-solved-please-help/#findComment-457946 Share on other sites More sharing options...
cooldude832 Posted February 4, 2008 Share Posted February 4, 2008 a nonregex solution <?php $file = ""; $data = file_get_contents($file); $data = strip_tag($data,"<script>"); $data = explode("<script",$data); foreach($data as $value){ $temp = strpos("</script>",$value); $scripts[] = substr($value,0,$temp); } print_r($temp); Quote Link to comment https://forums.phpfreaks.com/topic/89427-solved-please-help/#findComment-457953 Share on other sites More sharing options...
jeet_0077 Posted February 4, 2008 Author Share Posted February 4, 2008 Sasa, Thanks this works fine now I have the contents in the array. Now I have the array as: [1] => buildScheduleDiv('scottcam','♫ScottKam♫','http://static.stickam.com/media/image/converted/thumb/1747/9798/9/0d87768c-cfd4-11dc-87c9-b9d39bf5edbe.jpg','165312','Aphex Studio Sessions w/ SCOTTKAM','Updates on my Music','Mon, 04 Feb 2008 21:15:00 +0000','Mon, 04 Feb 2008 23:15:00 +0000') Here if you can help me as my intention is to get each item from the array. If I store the values in a string variable and I can use string_replace() to get rid of buildScheduleDiv. But here I have one more problem as I need each value to be entered in the db. Ex: val1 = scottcam val2 = ScottKam val3 = http://static.stickam.com/media/image/converted/thumb/1747/9798/9/0d87768c-cfd4-11dc-87c9-b9d39bf5edbe.jpg','165312 and so. I can not use the explode function in the string as in the description part there may be a comma or in some other place as well. If u can figure out what would be the best thing to do. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/89427-solved-please-help/#findComment-457967 Share on other sites More sharing options...
cooldude832 Posted February 4, 2008 Share Posted February 4, 2008 who says explode kills commas? explode explodes at a given delimeter in my case the <script tag Quote Link to comment https://forums.phpfreaks.com/topic/89427-solved-please-help/#findComment-458035 Share on other sites More sharing options...
sasa Posted February 5, 2008 Share Posted February 5, 2008 try <?php $a = file_get_contents('http://www.stickam.com/viewCategorySchedule.do?category=show/css/en/category/show/schedule.css'); preg_match_all('/buildScheduleDiv\(([^)]+)\)/', $a, $b); $out = array(); for ($i = 1; $i<count($b[1]); $i++){ $out[] = explode(',', str_replace("'",'', $b[1][$i])); } print_r($out); ?> Quote Link to comment https://forums.phpfreaks.com/topic/89427-solved-please-help/#findComment-458464 Share on other sites More sharing options...
sasa Posted February 5, 2008 Share Posted February 5, 2008 or <?php $a = file_get_contents('http://www.stickam.com/viewCategorySchedule.do?category=show/css/en/category/show/schedule.css'); preg_match_all('/buildScheduleDiv\(\'([^\']+)\'\)/', $a, $b); $out = array(); for ($i = 1; $i<count($b[1]); $i++){ $out[] = explode("','", $b[1][$i]); } print_r($out); ?> Quote Link to comment https://forums.phpfreaks.com/topic/89427-solved-please-help/#findComment-458648 Share on other sites More sharing options...
jeet_0077 Posted February 5, 2008 Author Share Posted February 5, 2008 Saha, Thanks for your reply. The second one worked for me. Quote Link to comment https://forums.phpfreaks.com/topic/89427-solved-please-help/#findComment-458806 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.