开发者

php how can i get certain keywords form a text file?

So after several Advil's I think I need help

I am trying to make a script that lets the user upload a .txt file, the file will look like this as an example

           EXT. DUNKIN' DONUTS - DAY

           Police vehicles remain in the parking lot.  The determined
      开发者_Go百科     female reporter from the courthouse steps, MELINDA FUENTES
           (32), interviews Comandante Chitt, who holds a napkin to his
           jaw, like he cut himself shaving.

                               MELINDA
                     < Comandante Chitt, how does it
                     feel to get shot in the face? >

                               COMANDANTE CHITT
                     < Not too different than getting
                     shot in the arm or leg. >

                               MELINDA
                     < Tell us what happened. >

                               COMANDANTE CHITT
                     < I parked my car.
                         (indicates assault vehicle
                          in donut shop)
                     He aimed his weapon at my head.  I
                     fired seven shots. He stopped
                     aiming his weapon at my head. >

           Melinda waits for more, but Chitt turns and walks away into
           the roped-off crime scene. Melinda is confused for a second,
           then resumes smiling.

                               MELINDA
                     < And there you have it... A man of
                     few words. >

Ok, so based off of this what I want to do is this:

The PHP script looks at the file and counts 35 white spaces, since all files will have the same layout and never differ in white spaces I chose this as the best way to go.

for every 35 white spaces extract character 36 until the end of line.

Then tally up $character++

so in the end the output would look like


It looks like you have 2 characters in your script

Melinda

Commandante Chitt

using PHP to select distint names, and use the strtolower() to lower case the strings and ucfirst() to make the first letter upper-case

thats my project,

I'm at the stage where I'm going crazy trying to figure out how to count white-spaces and everything after that white space until the first white-space after the word IS a character name


Use this

substr_count($text, ' ');

so

<?php
$dog = 0;
foreach($file as $text){
  $number = substr_count($text, ' ');
if($number == 15){
  $dog++;
  //You can do things like save all of the dogs into an array here or similar
}
echo "You have: ".$dog." dogs in this file";
?>


Well you can do a split like:

$line = "+++++++++++++++cat:+Garfield";
$chars = split("", $line)

$i = 0;
while( $i < $chars.length && $chars[$i] == '+' ) $i++;
$i--;

switch($i)
  Case 7:
     $person = Substr($line, 7, ($chars.length - 7);
     break;

  Case 15: 
    $cat = Substr($line, 20, ($chars.length - 20);
    break;

And so on... you can use something like this

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜