简体   繁体   English

PHP如何获取某些关键字形成文本文件?

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

So after several Advil's I think I need help 因此,经过几次Advil的治疗后,我认为我需要帮助

I am trying to make a script that lets the user upload a .txt file, the file will look like this as an example 我正在尝试制作一个脚本,该脚本可让用户上传.txt文件,该文件看起来像这样的示例

           EXT. DUNKIN' DONUTS - DAY

           Police vehicles remain in the parking lot.  The determined
           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. PHP脚本会查看文件并计数35个空格,因为所有文件的布局都相同,并且空格之间永远不会有所不同,因此我选择将其作为最佳方法。

for every 35 white spaces extract character 36 until the end of line. 每35个空白处提取字符36,直到行尾。

Then tally up $character++ 然后计算$ character ++

so in the end the output would look like 所以最终输出看起来像


It looks like you have 2 characters in your script 您的脚本中似乎有2个字符

Melinda 梅琳达

Commandante Chitt 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 使用PHP选择不同的名称,并使用strtolower()将字符串小写,并使用ucfirst()使首字母大写

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 依此类推...您可以使用类似这样的内容

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM