hi,
this is probably not at all what you want, but i wrote it just in case.

<?
function pos1($numbers) {
        if ($numbers) {
                if ($numbers == '1')
                        return "only";
                if (ereg("^1.+", $numbers))
                        return "left";
                if (ereg(".+1$", $numbers))
                        return "right";
                if (ereg(".+(1).+", $numbers))
                        return "middle";
        }
        return false;
}
$text = "3, 2, 1, 4";
if pos1($text)
        echo pos1($text);
?>

if 1 is in the string it will return either "middle", "left", "right" or "only".. if 
it is not it will return false.

On Fri, 15 Nov 2002 08:49:23 -0800 (PST)
[EMAIL PROTECTED] (Mako Shark) wrote:

>I have a real problem that I can't seem to figure out.
>I need an ereg pattern to search for a certain string
>(below). All this is being shelled to a Unix grep
>command because I'm looking this up in very many
>files.
>
>I've made myself a <INPUT TYPE="HIDDEN" tag> that
>contains in the value attribute a list of
>comma-delimited numbers. I need to find if a certain
>number is in these tags (and each file contains one
>tag). I need an ereg statement that will let me search
>these lines to see if a number exists, obviously in
>the beginning or the end or the middle or if it's the
>only number in the list. Here's what I mean (searching
>for number 1):
>
><INPUT TYPE = "HIDDEN" NAME = "numbers" VALUE =
>"1,2,3,4,5">   //beginning
>
><INPUT TYPE = "HIDDEN" NAME = "numbers" VALUE =
>"0,1,2,3,4,5">   //middle
>
><INPUT TYPE = "HIDDEN" NAME = "numbers" VALUE =
>"5,4,3,2,1">   //end
>
><INPUT TYPE = "HIDDEN" NAME = "numbers" VALUE = "1">  
> //only
>
>This is frustrating me, because each solution I come
>up with doesn't work. Here is my grep/ereg statement
>so far:
>
>$commanumberbeginning = "[[0-9]+,]*"; //this allows 0
>or more numbers before it, and if there are any, they
>must have 1 or more digits followed by a comma
>
>$commanumberend = "[,[0-9]+]*"; // this allows 0 or
>more numbers after it, and if there are any, they must
>have a comma followed by 1 or more digits
>
>$ereg-statement=$commanumberbeginning .
>$numbertosearchfor . $commanumberbeginning;
>//$numbertosearchfor will be obtained through a select
>control in a form
>
>grep '<INPUT TYPE = "HIDDEN" NAME = "numbers" VALUE =
>"$ereg-statement">' *.html
>
>This problem is kicking my butt. Any help?
>
>__________________________________________________
>Do you Yahoo!?
>Yahoo! Web Hosting - Let the expert host your site
>http://webhosting.yahoo.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to