is it possible to extract certain strings based off a predefined white-space count?
Posted
by
s2xi
on Stack Overflow
See other posts from Stack Overflow
or by s2xi
Published on 2011-01-13T03:30:51Z
Indexed on
2011/01/13
3:53 UTC
Read the original article
Hit count: 329
php
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
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 distinct 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
© Stack Overflow or respective owner