php-general Digest 21 Aug 2012 23:26:26 -0000 Issue 7932

Topics (messages 318786 through 318789):

Re: extract Occurrences AFTER ... and before "-30-"
        318786 by: Robert Cummings
        318787 by: Robert Cummings

Re: [PHP-DB] echo into variable or the like
        318788 by: Daniel Brown

set up mass virtual hosting with apache/nginx and PHP ... best practice 2012?
        318789 by: D. Dante Lorenso

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 ---
On 12-08-21 12:32 AM, John Taylor-Johnston wrote:


This is usually a first-year CS programming problem (word frequency
counts) complicated a little bit by needing to extract the text.
You've started off fine, stripping tags, converting to lower case,
you'll want to either convert or strip HTML entities as well, deciding
what you want to do with plurals and words like "you're", "Charlie's",
"it's", etc, also whether something like RFC822 is a word or not
(mixed letters and numbers).

When you've arranged all that, splitting on white space is trivial:

$words = preg_split('/[[:space:]]+/',$text);

and then you just run through the words building an associative array
by incrementing the count of each word as the key to the array:

foreach ($words as $word) {
      $freq[$word]++;
}

For output, you may want to sort the array:

ksort($freq);

That's awesome. Thanks!
Let me start with my first problem:

I want to extract All Occurrences of text AFTER "News Releases" and
before "-30-".

http://www.cegepsherbrooke.qc.ca/~languesmodernes/test/test.html

How do I do that?

Yeah, I am still asking first year questions :)) Every project brings
new challenges.

You can use strpos() to find the location of "News Releases" then you can again use strpos() to find the location of "-- 30 --" but you will want to feed strpos() an offset for matching "-- 30 --" (specifically the position found for "News Releases"). This ensures that you only match on "-- 30 --" when it comes after "News Releases". Once you have your beginning and start offsets you can use substr() to create a substring of the interesting excerpt. Once you have the excerpt in hand you can go back to JTJ's recommendation above.

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--- End Message ---
--- Begin Message ---
On 12-08-21 01:11 AM, Robert Cummings wrote:
On 12-08-21 12:32 AM, John Taylor-Johnston wrote:


This is usually a first-year CS programming problem (word frequency
counts) complicated a little bit by needing to extract the text.
You've started off fine, stripping tags, converting to lower case,
you'll want to either convert or strip HTML entities as well, deciding
what you want to do with plurals and words like "you're", "Charlie's",
"it's", etc, also whether something like RFC822 is a word or not
(mixed letters and numbers).

When you've arranged all that, splitting on white space is trivial:

$words = preg_split('/[[:space:]]+/',$text);

and then you just run through the words building an associative array
by incrementing the count of each word as the key to the array:

foreach ($words as $word) {
       $freq[$word]++;
}

For output, you may want to sort the array:

ksort($freq);

That's awesome. Thanks!
Let me start with my first problem:

I want to extract All Occurrences of text AFTER "News Releases" and
before "-30-".

http://www.cegepsherbrooke.qc.ca/~languesmodernes/test/test.html

How do I do that?

Yeah, I am still asking first year questions :)) Every project brings
new challenges.

You can use strpos() to find the location of "News Releases" then you
can again use strpos() to find the location of "-- 30 --" but you will
want to feed strpos() an offset for matching "-- 30 --" (specifically
the position found for "News Releases"). This ensures that you only
match on "-- 30 --" when it comes after "News Releases". Once you have
your beginning and start offsets you can use substr() to create a
substring of the interesting excerpt. Once you have the excerpt in hand
you can go back to JTJ's recommendation above.

Sorry... *YOU* are JTJ, but you trimmed the post including the responder's name (which you should leave intact when trimming). I defer (I think) to tamouse's recommendation above.

Cheers,
Rob.
--
E-Mail Disclaimer: Information contained in this message and any
attached documents is considered confidential and legally protected.
This message is intended solely for the addressee(s). Disclosure,
copying, and distribution are prohibited unless authorized.

--- End Message ---
--- Begin Message ---
On Tue, Aug 21, 2012 at 12:01 AM,  <s....@optusnet.com.au> wrote:
> Hi, this is my first post so forgive me if I missed a rule and do something 
> wrong.
>
> I have this code,
>
> echo $_SERVER['PHP_SELF']."?";
> foreach ($_GET as $urlvar=>$urlval)
> echo $urlvar."=".$urlval."&";
>
> It works by it’s self.
> I want to insert the output in a table.  Is there a way to ‘echo’ into a 
> variable(i.e. make the output of this echo the value of a variable) or am I 
> on the wrong track all together?

    This question actually belongs on the PHP General mailing list.

    As for echoing into a variable, the only way that's really
possible is with output buffering (ob_start(), ob_get_contents(),
ob_end_clean(), et al).  However, you don't need (and shouldn't want)
to do this here.  Instead, as your snippet really won't do much of
anything useful, you should (entirely) rewrite your code to look
something like this, for an HTML table:

    <?php
        echo $_SERVER['PHP_SELF'].'?'.PHP_EOL;
        echo '<table>'.PHP_EOL;
        foreach ($_GET as $key => $value) {
            echo ' <tr>'.PHP_EOL;
            echo '  <td>'.$key.'</td>'.PHP_EOL;
            echo '  <td>'.$value.'</td>'.PHP_EOL;
            echo ' </tr>'.PHP_EOL;
        }
        echo '</table>';
    ?>

    However, since it looks almost as if you're trying to build a
query string based upon the supplied GET variables, you may want to
try looking into http_build_query().

-- 
</Daniel P. Brown>
Network Infrastructure Manager
http://www.php.net/

--- End Message ---
--- Begin Message ---
All,

I need to set up a server to enable 5,000 students to have web hosting provided by the school with PHP and MySQL support. I'm trying to figure out what is the best way to do this.

We have Active Directory and are using Centrify to authenticate usernames and passwords on our Linux servers. I am imagining it would be great if we use something like ExecCGI to ensure that PHP runs as the user that owns the files. We would then provide FTP access to the files and FTP would authenticate against Active Directory making sure to set the proper user/group on files when uploaded.

I see that PHP-FPM exists: http://php-fpm.org and it claims "Ability to start workers with different uid/gid/chroot/environment and different php.ini (replaces safe_mode)" which is exactly what I'm looking for. It also claims "PHP-FPM is now included in PHP core as of PHP 5.3.3." so that's good.

I also read about the greatness that is NGinX: http://nginx.org though I don't know if I can use it because I think I also need to use .htaccess files. I need a way for students to be able to password protect their directories and files. If there's another way using NGinX or Apache, that's good too. I know of no other way.

Here is an interesting article from 2009:
http://www.howtoforge.com/how-to-set-up-mass-virtualhosting-with-apache2-mod_rewrite-mod_userdir-mod_suexec-on-centos-5.3

That uses mod_rewrite to attempt something like what I'm trying to do ... and then, Apache has mod_vhost_alias:
http://httpd.apache.org/docs/2.2/mod/mod_vhost_alias.html

So, I see a lot of information out there. Apache, NginX, ExecCGI, FastCGI, mod_vhost_alias, mod_rewrite, SuExec, mod_userdir. I suspect some of these methods are old and out of date.

In my ideal situation:

 - users would be created in AD and would exist on the OS

 - student domain names would look like:
        http://<username>.student.school.edu/ - OR -
        http://student.school.edu/<username>/

 - file directories would look like:
        /mnt/somedir/<username>/docroot

 - students would be able to create PHP applications executed with
        their own permissions

 - I would be able to configure all 5,000 accounts with a single
        configuration (1 virtual host rule?)

Do you know what the "best practices" are for now ... here in 2012?

-- Dante


--- End Message ---

Reply via email to