[PHP] Re: Ereg headache

2002-11-15 Thread Gustaf Sjoberg
or.. if there can be only one instance of the number you can easily calculate it's 
position with

strlen($numbers)

and strpos($numbers, "1");

if strlen returns 5 and strpos 5 you'll know it was far right.. if strpos returns 1 
and strlen >1 it's to the left.. and if strpos < strlen but not 1 it's in the middle.. 
etc.

On Sat, 16 Nov 2002 00:04:50 +0100
[EMAIL PROTECTED] (Gustaf Sjoberg) wrote:

>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  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):
>>
>>>"1,2,3,4,5">   //beginning
>>
>>>"0,1,2,3,4,5">   //middle
>>
>>>"5,4,3,2,1">   //end
>>
>>  
>> //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 '>"$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




[PHP] Re: Ereg headache

2002-11-15 Thread Gustaf Sjoberg
hi,
this is probably not at all what you want, but i wrote it just in case.



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  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):
>
>"1,2,3,4,5">   //beginning
>
>"0,1,2,3,4,5">   //middle
>
>"5,4,3,2,1">   //end
>
>  
> //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 '"$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




Re: [PHP] ereg_replace();

2002-11-13 Thread Gustaf Sjoberg
Ah, very nice Ernest. thanks a lot.

the nice thing is that i read and understood the regexp so i got a great deal out of 
having this problem ;-)

cheers,
GS

On Wed, 13 Nov 2002 08:28:30 +0100
[EMAIL PROTECTED] (Ernest E Vogelsinger) wrote:

>At 01:59 13.11.2002, Gustaf Sjoberg said:
>[snip]
>>hi,
>>i tried to implement the code, but it does not work if the string:
>>
>>a) doesnt contain any ..
>>b) doesnt contain any 
>>c) doesnt contain any 
>>d) contains multiple ..'s
>>
>>so i altered it a little and this is what i came up with:
>
>Here's my original function, now tested and bugs removed, together with
>some comments:
>
>function remove_br_in_pre($string)
>{
>$re1 = '/(.*?)(.*?)<\/pre>(.*)/is';
>$re2 = '/\n?/is';
>
>// setting a variable to "null" defines it, so we don't get
>// a warning for an undefined variable at the first concatenation.
>// unset($result) doesn't define it, and is unnecessary
>// as it is not "set" at this moment.
>$result = null;
>
>// this generates a loop that will remove multiple pre's
>while ($string) {
>
>// my original assignment ($arMatch = preg_match(...)) was wrong.
>// preg_match returns 1 on match, and 0 on no match.
>if (preg_match($re1, $string, $arMatch)) {
>$result .= $arMatch[1];
>
>// sorry, forgot to keep the  pairs...
>// you need to add a line break instead of the 
>// to keep your code formatted
>$result .= ''.preg_replace($re2, "\n", $arMatch[2]).'';
>$string = $arMatch[3];
>}
>else break;
>}
>
>// if there are no  pairs, $string will be unmodified and the
>// loop will immediately break out at the first attempt. This appends
>// either the whole $string, or the remaining $string, to the result.
>$result .= $string;
>return $result;
>}
>
>>now, i've tried it in a few different scenarios and it seems to be working, 
>>although the function might be redundant and far from pretty - it gets the 
>>job done. however, i have a question; what does the "is" in //is denote? ;-) 
>>(doesnt it feel great to have code sniplets you have no idea what they do in 
>>your scripts? ;-))
>
>The regex modifiers:
>   i - make that case independent, so , , and others are matched
>   s - treat the input as a single line, don't stop at a newline
>
>>also, do you see any direct "bugs slash features" in the current function? 
>
>Not that I'd be aware of...
>
>>thanks in anticipation,
>
>You're most welcome :)
>
>-- 
>   >O Ernest E. Vogelsinger
>   (\)ICQ #13394035
>^ http://www.vogelsinger.at/
>
>


-- 
Gustaf Sjoberg <[EMAIL PROTECTED]>
 <(" <) <(" )> <( ")> (> ")> 

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




Re: [PHP] ereg_replace();

2002-11-12 Thread Gustaf Sjoberg
hi,
i tried to implement the code, but it does not work if the string:

a) doesnt contain any ..
b) doesnt contain any 
c) doesnt contain any 
d) contains multiple ..'s

so i altered it a little and this is what i came up with:

)(.*?)(<\/pre>)(.*)/is', $string))
{
if (!preg_match('//is', $string))
return $string;
else
$string .= "";
}
while ($string)
{
preg_match('/(.*?)(.*?)(<\/pre>)(.*)/is', $string, $arMatch); 
  
if (is_array($arMatch))
{
$result .= $arMatch[1];
$result .= str_replace('','',$arMatch[2]);
$result .= $arMatch[3];
if (!preg_match('//is', $arMatch[4]))
{
$result .= $arMatch[4];
return $result;
}
$string = $arMatch[4];
}
else break;
}
}
//test string
$param = 
"testtesttestingtestingtesttesttesttesttesttestingtest";
echo remove_br_in_pre($param);
?>

now, i've tried it in a few different scenarios and it seems to be working, although 
the function might be redundant and far from pretty - it gets the job done. however, i 
have a question; what does the "is" in //is denote? ;-) (doesnt it feel great to have 
code sniplets you have no idea what they do in your scripts? ;-))

also, do you see any direct "bugs slash features" in the current function? i'm not 
usually asking someone who spends his freetime helping others "baby sit" my code, but 
this was my first day using regular expressions so i've been taking a few sure shots.. 
so it would be great if you could just take a quick glance at it.

thanks in anticipation,
GS

On Tue, 12 Nov 2002 18:57:04 +0100
[EMAIL PROTECTED] (Ernest E Vogelsinger) wrote:

>At 18:44 12.11.2002, Gustaf Sjoberg spoke out and said:
>[snip]
>>many thanks, and kudos for the quick reply. i will try that right away!
>>
>>as a sub-question, do you mind telling me where you learned regexp? i've 
>>been searching google all day with no luck, i've just find more or less 
>>basic regexp guides. did you learn through practice or do you have a secret 
>>source? ;-)
>[snip] 
>
>This stems from my old Perl days - I recommend reading the "Camel Book" :)
>
>Refer to http://www.perldoc.com/perl5.6/pod/perlre.html and eat this page -
>you'll be a RegEx whiz in seconds (naahh - it takes a bit longer ;->)
>
>
>-- 
>   >O Ernest E. Vogelsinger 
>   (\) ICQ #13394035 
>^ http://www.vogelsinger.at/
>


-- 
Gustaf Sjoberg <[EMAIL PROTECTED]>
 <(" <) <(" )> <( ")> (> ")> 

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




Re: [PHP] ereg_replace();

2002-11-12 Thread Gustaf Sjoberg
many thanks, and kudos for the quick reply. i will try that right away!

as a sub-question, do you mind telling me where you learned regexp? i've been 
searching google all day with no luck, i've just find more or less basic regexp 
guides. did you learn through practice or do you have a secret source? ;-)

On Tue, 12 Nov 2002 18:35:55 +0100
[EMAIL PROTECTED] (Ernest E Vogelsinger) wrote:

>At 17:49 12.11.2002, Gustaf Sjoberg spoke out and said:
>[snip]
>>Hi,
>>i'm trying to replace every instance of "" within the ".." 
>>tags. i want all other breakrows to remain the same.
>>
>>i've tried numerous regular expressions, but i can't find a way to just 
>>replace the breakrows.. it replaces _everything_ bewteen  and .
>[snip] 
>
>You need a two-phase operation on this:
>
>1) isolate all  elements
>   preg_match('/(.*?)(.*?)<\/pre>(.*)/is', $string, $armatch);
>
>$armatch now contains:
>   [0] all, ignore this
>   [1] everything before 
>   [2] everything within 
>   [3] the rest after 
>
>2) go on and replace all 's here:
>   preg_replace('/\n?/is', "\n", $armatch[2]);
>
>The whole stuff would look something like
>
>/* UNTESTED */
>function kill_br_within_pre($string)
>{
>$re1 = '/(.*?)(.*?)<\/pre>(.*)/is';
>$re2 = '/\n?/is';
>$result = null;
>
>while ($string) {
>$armatch = preg_match($re1, $string, $arMatch);
>if (is_array($arMatch)) {
>$result .= $arMatch[1];
>$result .= preg_replace($re2, "\n", $arMatch[2]);
>$string = $arMatch[3];
>}
>else break;
>}
>    $result .= $string;
>return $result;
>}
>
>This assumes that all  are properly closed with . As said, I
>didn't test, but it should work this or a similar way.
>
>
>-- 
>   >O Ernest E. Vogelsinger 
>   (\) ICQ #13394035 
>^ http://www.vogelsinger.at/
>


-- 
Gustaf Sjoberg <[EMAIL PROTECTED]>
 <(" <) <(" )> <( ")> (> ")> 

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




[PHP] Re: get the output from a program

2002-11-12 Thread Gustaf Sjoberg
this is just a shot in the dark, beware. but i think you could make use of the 
system() function and pass the output to a file.

ex. system('df > ~/public_html/output.tmp');

but i've never tried the function, try to search php.net functions for system

On Tue, 12 Nov 2002 12:33:09 -0500
[EMAIL PROTECTED] (Greg) wrote:

>Hi-
>Is there a way in PHP to execute a program and then have it pass its output
>back to PHP?  Say I wanted to return the value that running "df" produced
>and put it in a web page?  Thanks!!
>-Greg
>
>


-- 
Gustaf Sjoberg <[EMAIL PROTECTED]>
 <(" <) <(" )> <( ")> (> ")> 

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




[PHP] ereg_replace();

2002-11-12 Thread Gustaf Sjoberg
Hi,
i'm trying to replace every instance of "" within the ".." tags. i want 
all other breakrows to remain the same.

i've tried numerous regular expressions, but i can't find a way to just replace the 
breakrows.. it replaces _everything_ bewteen  and .

example $string:

test
test
test

testing
testing

test
test

i want that to look like:

test
test
test

testing
testing

test
test

-- 
Gustaf Sjoberg <[EMAIL PROTECTED]>
 <(" <) <(" )> <( ")> (> ")> 

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