php-general Digest 3 Sep 2012 04:47:59 -0000 Issue 7948

Topics (messages 318946 through 318951):

array_push
        318946 by: John Taylor-Johnston
        318947 by: Frank Arensmeier

Re: extract Occurrences AFTER ... and before "-30-"
        318948 by: tamouse mailing lists
        318949 by: John Taylor-Johnston
        318950 by: tamouse mailing lists
        318951 by: John Taylor-Johnston

Administrivia:

To subscribe to the digest, e-mail:
        php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
        php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
        php-gene...@lists.php.net


----------------------------------------------------------------------
--- Begin Message ---
How can I clean this up?
My approach would be to split the hole text into smaller chunks (with e.g. explode()) and extract the interesting parts with a regular expression. Maybe this will give you some ideas:
$chunks = explode("-30-", $mystring);
foreach($chunks as $chunk) {
         preg_match_all("/News Releases\n(.+)/s", $chunk, $matches);
         var_dump($matches[1]);
}
The regex matches all text between "News Releases" and the end of the chunk.
2) How could I suck it into one nice easy to handle array?

|$mynewarray=|array {
  [0]=> "Residential Fire Determined to be Accidental in Nature ..."
  [1]=> "Arrest Made in Residential Fire ..."
}
I was hoping preg_match_all would return strings. I w/as hoping |$matches[1] was a string.|/

source: http://www.cegepsherbrooke.qc.ca/~languesmodernes/test/test4.phps
result: http://www.cegepsherbrooke.qc.ca/~languesmodernes/test/test4.php

This is ugly. How can I clean this up like this?

$mynewarray= array {
  [0]=> "Residential Fire Determined to be Accidental in Nature ..."
  [1]=> "Arrest Made in Residential Fire ..."
}

I wanted to push $matches[] (which I hoped was a string, not an array). I probably don't understand what preg_match_all did.

Now I have arrays nested inside the array(). How can I clean it up?

http://www.cegepsherbrooke.qc.ca/~languesmodernes/test/test4.php


--- End Message ---
--- Begin Message ---
2 sep 2012 kl. 19.48 skrev John Taylor-Johnston:

> How can I clean this up?
>>> My approach would be to split the hole text into smaller chunks (with e.g. 
>>> explode()) and extract the interesting parts with a regular expression. 
>>> Maybe this will give you some ideas:
>>>> $chunks = explode("-30-", $mystring);
>>>> foreach($chunks as $chunk) {
>>>>         preg_match_all("/News Releases\n(.+)/s", $chunk, $matches);
>>>>         var_dump($matches[1]);
>>>> }
>>>> The regex matches all text between "News Releases" and the end of the 
>>>> chunk.
>> 2) How could I suck it into one nice easy to handle array?
>> 
>> |$mynewarray=|array {
>>  [0]=> "Residential Fire Determined to be Accidental in Nature ..."
>>  [1]=> "Arrest Made in Residential Fire ..."
>> } 
> I was hoping preg_match_all would return strings.  I w/as hoping |$matches[1] 
> was a string.|/
> 
> source: http://www.cegepsherbrooke.qc.ca/~languesmodernes/test/test4.phps
> result: http://www.cegepsherbrooke.qc.ca/~languesmodernes/test/test4.php

Have you read up on 'preg_match_all' in the manual? What makes you think that 
preg_match_all returns strings? "$matches[1]", in the above case contains an 
array with all matches from the parenthesized subpattern, which is "(.+).

> This is ugly. How can I clean this up like this?
> 
> $mynewarray= array {
>  [0]=> "Residential Fire Determined to be Accidental in Nature ..."
>  [1]=> "Arrest Made in Residential Fire ..."
> }

Why not add two lines of code within the first loop?

$chunks = explode("-30-", $mystring);
foreach($chunks as $chunk) {
    preg_match_all("/News Releases\n(.+)/s", $chunk, $matches);
    foreach($matches[1] as $matched_text_line) {
        $mynewarray[] = $matched_text_line;
    }
}

Besides the regex, this is pretty basic php. 

/frank

--- End Message ---
--- Begin Message ---
On Sun, Sep 2, 2012 at 11:31 AM, John Taylor-Johnston
<jt.johns...@usherbrooke.ca> wrote:
> I'll never get it. Newest work on top of the pile, instead of digging :))

Usually order reverse in flow conversations your do?

--- End Message ---
--- Begin Message ---
"tamouse mailing lists wrote:"
Just to prove me right, our mail clients start quoting from the top too :)p

tamouse mailing lists wrote:
On Sun, Sep 2, 2012 at 11:31 AM, John Taylor-Johnston
<jt.johns...@usherbrooke.ca> wrote:
I'll never get it. Newest work on top of the pile, instead of digging :))
Usually order reverse in flow conversations your do?



--- End Message ---
--- Begin Message ---
On Sun, Sep 2, 2012 at 7:57 PM, John Taylor-Johnston
<jt.johns...@usherbrooke.ca> wrote:
> Just to prove me right, our mail clients start quoting from the top too :)p

Exactly. The quoting starts from the *top*. The problem is that the
cursor to start typing is also put there by default.
Step back before MS Outlook started that trend, which, of course, one
could *change* if one wanted to. The standard proforma for mail,
usenet, notes, bbs's, and most other forms (c.f. the Well, etc) were
all bottom post, or even better intermingled with ONLY the relevant
parts used, not the entire message.

--- End Message ---
--- Begin Message ---
tamouse mailing lists wrote:
On Sun, Sep 2, 2012 at 7:57 PM, John Taylor-Johnston
<jt.johns...@usherbrooke.ca> wrote:
Just to prove me right, our mail clients start quoting from the top too :)p
Exactly. The quoting starts from the *top*. The problem is that the
cursor to start typing is also put there by default.
Step back before MS Outlook started that trend, which, of course, one
could *change* if one wanted to. The standard proforma for mail,
usenet, notes, bbs's, and most other forms (c.f. the Well, etc) were
all bottom post, or even better intermingled with ONLY the relevant
parts used, not the entire message.

I like the part where you said the cursor starts a the top by default :)p
But hey, I can follow established "convention" and bottom post.
I'm a renegade. Richard Stallman is my hero. :) But let's not tease each other too much and block the very good work of this list.

I have always been a fan of PHP, and this php-general list. I used to PERL, but found the posters impolite to the extent of nasty. Since this list got started, everyone has been especially nice, polite and helpful. And that is why I come back. I'm a newbie at best. I ask questions. I "try" to learn from pseudo coding, applying that to what I can create. When I hit a juncture or rough patch, I post my code and you folks help me out.

Thanks everyone! :)

John

--- End Message ---

Reply via email to