How can I ignore “XXX” titles in my data parsing script?

依然范特西╮ 提交于 2020-01-06 08:14:11

问题


I've tried and it doesn't seem to work. Any help would be greatly appreciated.

CODE:

foreach (glob('mov/Alene*.mov') as $filename){ 
    $theData = file_get_contents($filename) or die("Unable to retrieve file data");
}

$string = $theData;
$titles = explode("\n", $string);

function getInfo($string){
    $Ratings = ['G', 'PG', 'PG-13', 'R', 'NR', 'XXX'];
    $split = preg_split("/\"(.+)\"/", $string, 0, PREG_SPLIT_DELIM_CAPTURE);
    if(count($split) == 3){ 
        preg_match("/(".implode("|", $Ratings).")\s/", $split[0], $matches);
        $rating = $matches[0];
        return ["title" => $split[1], "rating" => $rating];
    }
    return false;
}




$infolist = array();
foreach($titles as $title){
    $info = getInfo($title);
    if($info !== false){
    $infolist[] = $info;
    }
}

usort($infolist, "infosort");

function infosort($lhs,$rhs) {
  return strcmp($lhs['rating'], $rhs['rating']);
}

foreach ($infolist as $info) {
        echo "<div style ='margin-bottom: 3px; text-align: center;
          font:13px Verdana,tahoma,sans-serif;color:green;'> 
           {$info["title"]} : {$info["rating"]}</div>";
}


//------------------LOGO---------------------//

echo "<div style='text-align:center; margin-top: 20px;'><img src='imgs/shclogo.png'
alt='Logo' width='200' height='133'/></div>";

//-------------------------------------------//
?>

I've tried adding:

if($info["rating"]!=="XXX")//foreach $infolist as $info... 

I've also tried adding that in the source where preg_match is but that didn't work either. It all still displays the "XXX" titles.

I just need to figure out how to ignore the XXX titles and display everything else.

The output originally looks like this...

(HD) Safe House : R
(HD) Wanderlust : R
(HD) Machine Gun Preacher : R
(HD) Silent House : R
(HD) Seeking Justice : R
Adult title 1 : XXX
Adult title 2 : XXX
Adult title 3 : XXX
Adult title 4 : XXX

There are many more XXX titles, but I can't display them all. Any help and you'd be my life saver.


回答1:


After foreach ($infolist as $info) {, add:

if ($info['rating'] == 'XXX') { continue; };

This will skip over the XXX-rated titles before attempting to output anything for them, which should have the effect you desire.



来源:https://stackoverflow.com/questions/17029365/how-can-i-ignore-xxx-titles-in-my-data-parsing-script

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!