[PHP] reg-ex

2002-03-25 Thread John Fishworld

How can I change this to accept spaces as well ?

(ereg("^[A-Za-zÀ-ÖØ-öø-ÿ]*$", $str))



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




[PHP] Reg Ex

2008-10-31 Thread Kyle Terry
I'm horrible with regular expression. I need to match the text before a file
extension. So if the file is called US.123.kyle.20081029.zip, I would then
need to match US.123.kyle.20081029.

Thanks!

-- 
Kyle Terry | www.kyleterry.com


[PHP] reg-ex problem

2001-02-07 Thread Lee Stretton

Hi,

I am using regular expressions in a php program to decide what should be
done next. I am having a problem with one of my regex's. The following
is the code i am using:



for( $i = 0; $i < sizeof( $arg ); $i++ )
{
if( $arg[$i] == '' )
{
continue;
}

if( preg_match( "/^\d{4}-\d{4}$/", $arg[$i], $matches ) )
{
$season = $matches[0];
}
elseif( preg_match( "/^[a-zA-Z]+$/", $arg[$i], $matches ) )
{
if( ! isset( $display ) )
{
$display = $matches[0];
}
}   
elseif( preg_match( "/^\d+$/", $arg[$i], $matches ) )
{
$value = $matches[0];
}
elseif( preg_match( "/(div\d|prem)/", $arg[$i], $matches ) )
{
$division = $matches[0];
}echo $arg[$i]."***"; 
echo $division;
}



The first 3 work fine, but the last one "/(div\d|prem)/" doesnt work
properly. It does work if I have say div1, but if I have prem it doesnt
work at all. I have tried changing the regex so it only contains
"/prem/" and it still doesnt work. can anyone tell me what is wrong with
this code, or is it just a bug in my version of php?

Thanks in advance,

Lee Stretton.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] reg-ex please

2002-04-27 Thread John Fishworld

Help please from one of the reg-ex experts out there please !

I'm trying to find the pattern &#(5 number);
example 𑃸

This works
$code[$i] = ereg_replace("&#([0-9])+" , "replace\\0.bing" , $code[$i] );

and I get back replace 𑃸.bing

but I also want to lose the &# and the ;
so I get back 69880.bing

At the moment I just re search and remove the like this
$code[$i] = ereg_replace('&#','',$code[$i]);
$code[$i] = ereg_replace(';','',$code[$i]);

but I'm sure that theortetically I can do it in one step !
Can anyone help !
Thanks in advance



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




[PHP] reg-ex again

2002-04-29 Thread John Fishworld

I'm trying to find files in my array
for example
="lg_imode.gif"
and
="/db/imodeklein/edgar-IMODE-1-.gif"

I want to differentiate between the files with slash at the front and ones
without so that
I can add a server path !
but as usual I' m having problems with the correct regex

At the moment I've got this to find files with forward slash
eregi_replace("([^\"]+[/+]+[a-z_/-]+[gif]+[/$])"
and it seems to work.(although I think it's wrong)

And I'm trying this to find the files without the slash at the front
eregi_replace("([^\"]+(a-z_)+[gif]$)"

which is definately not working.

help !
thanks !






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




Re: [PHP] reg-ex

2002-03-25 Thread Rasmus Lerdorf

"^[ A-Za-z---]*$"

On Mon, 25 Mar 2002, John Fishworld wrote:

> How can I change this to accept spaces as well ?
>
> (ereg("^[A-Za-zÀ-ÖØ-öø-ÿ]*$", $str))
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>


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




Re: [PHP] Reg Ex

2008-10-31 Thread Stut

On 31 Oct 2008, at 12:27, Kyle Terry wrote:
I'm horrible with regular expression. I need to match the text  
before a file
extension. So if the file is called US.123.kyle.20081029.zip, I  
would then

need to match US.123.kyle.20081029.


No regex required. Why do people think everything like this needs a  
regex??


  http://php.net/pathinfo

-Stut

--
http://stut.net/

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



Re: [PHP] Reg Ex

2008-10-31 Thread Kyle Terry
I thought of a couple other ways anyway...

basename($file, '.zip')
substr($file, 0, -4)

On Fri, Oct 31, 2008 at 5:33 AM, Stut <[EMAIL PROTECTED]> wrote:

> On 31 Oct 2008, at 12:27, Kyle Terry wrote:
>
>> I'm horrible with regular expression. I need to match the text before a
>> file
>> extension. So if the file is called US.123.kyle.20081029.zip, I would then
>> need to match US.123.kyle.20081029.
>>
>
> No regex required. Why do people think everything like this needs a regex??
>
>  http://php.net/pathinfo
>
> -Stut
>
> --
> http://stut.net/
>



-- 
Kyle Terry | www.kyleterry.com


Re: [PHP] Reg Ex

2008-10-31 Thread Eric Butera
On Fri, Oct 31, 2008 at 8:41 AM, Kyle Terry <[EMAIL PROTECTED]> wrote:
> I thought of a couple other ways anyway...
>
> basename($file, '.zip')
> substr($file, 0, -4)
>
> On Fri, Oct 31, 2008 at 5:33 AM, Stut <[EMAIL PROTECTED]> wrote:
>
>> On 31 Oct 2008, at 12:27, Kyle Terry wrote:
>>
>>> I'm horrible with regular expression. I need to match the text before a
>>> file
>>> extension. So if the file is called US.123.kyle.20081029.zip, I would then
>>> need to match US.123.kyle.20081029.
>>>
>>
>> No regex required. Why do people think everything like this needs a regex??
>>
>>  http://php.net/pathinfo
>>
>> -Stut
>>
>> --
>> http://stut.net/
>>
>
>
>
> --
> Kyle Terry | www.kyleterry.com
>

Who says every file will have an extension?  Who says they're all .+3
chars?  When I first started php I tried that and it failed in a lot
of places.

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



Re: [PHP] Reg Ex

2008-10-31 Thread Warren Windvogel

Eric Butera wrote:

Who says every file will have an extension?  Who says they're all .+3
chars?  When I first started php I tried that and it failed in a lot
of places.


I've also run into that problem in the past. The way that I could work 
around all these issues was to document naming conventions for the files 
and validate these before using the regex to obtain the necessary 
information.


Regards
Warren

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



Re: [PHP] Reg Ex

2008-10-31 Thread Eric Butera
On Fri, Oct 31, 2008 at 9:09 AM, Warren Windvogel
<[EMAIL PROTECTED]> wrote:
> Eric Butera wrote:
>>
>> Who says every file will have an extension?  Who says they're all .+3
>> chars?  When I first started php I tried that and it failed in a lot
>> of places.
>
> I've also run into that problem in the past. The way that I could work
> around all these issues was to document naming conventions for the files and
> validate these before using the regex to obtain the necessary information.
>
> Regards
> Warren
>

...or you could just use pathinfo and be done with it.  I work for
clients.  Clients shouldn't have to read a faq to upload a file.

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



Re: [PHP] Reg Ex

2008-10-31 Thread Daniel P. Brown
On Fri, Oct 31, 2008 at 7:44 AM, Eric Butera <[EMAIL PROTECTED]> wrote:
>
> Who says every file will have an extension?  Who says they're all .+3
> chars?  When I first started php I tried that and it failed in a lot
> of places.

.htaccess is a prime example of this.

-- 

http://www.parasane.net/
[EMAIL PROTECTED] || [EMAIL PROTECTED]
Ask me about our current hosting/dedicated server deals!

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



Re: [PHP] Reg Ex

2008-10-31 Thread Jochem Maas
Eric Butera schreef:
> On Fri, Oct 31, 2008 at 9:09 AM, Warren Windvogel
> <[EMAIL PROTECTED]> wrote:
>> Eric Butera wrote:
>>> Who says every file will have an extension?  Who says they're all .+3
>>> chars?  When I first started php I tried that and it failed in a lot
>>> of places.
>> I've also run into that problem in the past. The way that I could work
>> around all these issues was to document naming conventions for the files and
>> validate these before using the regex to obtain the necessary information.
>>
>> Regards
>> Warren
>>
> 
> ...or you could just use pathinfo and be done with it.  I work for
> clients.  Clients shouldn't have to read a faq to upload a file.

no. they generally believe that when they upload a CSV file in a field
very clearly marked "upload your FLASH file here" things should just work :-)

> 


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



Re: [PHP] Reg Ex

2008-10-31 Thread Eric Butera
On Fri, Oct 31, 2008 at 10:03 AM, Jochem Maas <[EMAIL PROTECTED]> wrote:
> Eric Butera schreef:
>> On Fri, Oct 31, 2008 at 9:09 AM, Warren Windvogel
>> <[EMAIL PROTECTED]> wrote:
>>> Eric Butera wrote:
 Who says every file will have an extension?  Who says they're all .+3
 chars?  When I first started php I tried that and it failed in a lot
 of places.
>>> I've also run into that problem in the past. The way that I could work
>>> around all these issues was to document naming conventions for the files and
>>> validate these before using the regex to obtain the necessary information.
>>>
>>> Regards
>>> Warren
>>>
>>
>> ...or you could just use pathinfo and be done with it.  I work for
>> clients.  Clients shouldn't have to read a faq to upload a file.
>
> no. they generally believe that when they upload a CSV file in a field
> very clearly marked "upload your FLASH file here" things should just work :-)
>
>>
>
>

:D

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



RE: [PHP] Reg Ex

2008-10-31 Thread Boyd, Todd M.
> -Original Message-
> From: Kyle Terry [mailto:[EMAIL PROTECTED]
> Sent: Friday, October 31, 2008 7:28 AM
> To: PHP General Mailing List
> Subject: [PHP] Reg Ex
> 
> I'm horrible with regular expression. I need to match the text before
a
> file
> extension. So if the file is called US.123.kyle.20081029.zip, I would
> then
> need to match US.123.kyle.20081029.

Someone suggested pathinfo() already... and brought up the issues of
extensions < 3 chars and files with no "basename" (i.e., ".htaccess")...

Checked out www.php.net/pathinfo, and ran a demo on my own machine. I
can't test the .htaccess problem, since I'm running Windows (and M$
won't let you have files that start with "."), but I tested it with
"a.b.c.d" and the extension was returned as "d". Basename was "a.b.c".

Sounds like it will do exactly what you are trying to accomplish. For
what it's worth, if I were to do it with a regular expression, I would
use:

$filename = "us.123.kyle.20081029.zip";
preg_match('/(.*)\..*$/', $filename, $match);

Check out www.regular-expressions.info ... the only excuse you can have
for not knowing is that you haven't tried to learn yet. ;)

HTH,


Todd Boyd
Web Programmer




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



Re: [PHP] Reg Ex

2008-10-31 Thread Kyle Terry
Thanks for the reply. For now I used substr($filename,0,-4) and that worked
perfectly. I need to learn reg ex badly :(.

On Fri, Oct 31, 2008 at 7:51 AM, Boyd, Todd M. <[EMAIL PROTECTED]> wrote:

> > -Original Message-
> > From: Kyle Terry [mailto:[EMAIL PROTECTED]
> > Sent: Friday, October 31, 2008 7:28 AM
> > To: PHP General Mailing List
> > Subject: [PHP] Reg Ex
> >
> > I'm horrible with regular expression. I need to match the text before
> a
> > file
> > extension. So if the file is called US.123.kyle.20081029.zip, I would
> > then
> > need to match US.123.kyle.20081029.
>
> Someone suggested pathinfo() already... and brought up the issues of
> extensions < 3 chars and files with no "basename" (i.e., ".htaccess")...
>
> Checked out www.php.net/pathinfo, and ran a demo on my own machine. I
> can't test the .htaccess problem, since I'm running Windows (and M$
> won't let you have files that start with "."), but I tested it with
> "a.b.c.d" and the extension was returned as "d". Basename was "a.b.c".
>
> Sounds like it will do exactly what you are trying to accomplish. For
> what it's worth, if I were to do it with a regular expression, I would
> use:
>
> $filename = "us.123.kyle.20081029.zip";
> preg_match('/(.*)\..*$/', $filename, $match);
>
> Check out www.regular-expressions.info ... the only excuse you can have
> for not knowing is that you haven't tried to learn yet. ;)
>
> HTH,
>
>
> Todd Boyd
> Web Programmer
>
>
>
>


-- 
Kyle Terry | www.kyleterry.com


Re: [PHP] Reg Ex

2008-10-31 Thread Daniel P. Brown
On Fri, Oct 31, 2008 at 9:53 AM, Kyle Terry <[EMAIL PROTECTED]> wrote:
> Thanks for the reply. For now I used substr($filename,0,-4) and that worked
> perfectly. I need to learn reg ex badly :(.

Before you do that, learn to read and follow along in an email
thread that you start.  We gave you perfect pointers as to (a) why
regexp's aren't needed in this case; and (b) how to better handle it.

Your substr() routine won't work as expected in all cases.
Imagine either an .htaccess file or an extensionless file named
`quagmire`.  You'll come up with `cess` and `mire`, respectively.

-- 

http://www.parasane.net/
[EMAIL PROTECTED] || [EMAIL PROTECTED]
Ask me about our current hosting/dedicated server deals!

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



Re: [PHP] Reg Ex

2008-10-31 Thread Diogo Neves
Hi all,

It depends on what he really want, but pathinfo really is a better option

My test worked perfectly on files with no extension and without name...



On Fri, Oct 31, 2008 at 2:57 PM, Daniel P. Brown
<[EMAIL PROTECTED]>wrote:

> On Fri, Oct 31, 2008 at 9:53 AM, Kyle Terry <[EMAIL PROTECTED]> wrote:
> > Thanks for the reply. For now I used substr($filename,0,-4) and that
> worked
> > perfectly. I need to learn reg ex badly :(.
>
> Before you do that, learn to read and follow along in an email
> thread that you start.  We gave you perfect pointers as to (a) why
> regexp's aren't needed in this case; and (b) how to better handle it.
>
>Your substr() routine won't work as expected in all cases.
> Imagine either an .htaccess file or an extensionless file named
> `quagmire`.  You'll come up with `cess` and `mire`, respectively.
>
> --
> 
> http://www.parasane.net/
> [EMAIL PROTECTED] || [EMAIL PROTECTED]
> Ask me about our current hosting/dedicated server deals!
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

-- 
Thanks,

Diogo Neves
Web Developer @ SAPO.pt by PrimeIT.pt


Re: [PHP] Reg Ex

2008-10-31 Thread Warren Windvogel

Eric Butera wrote:

...or you could just use pathinfo and be done with it.  I work for
clients.  Clients shouldn't have to read a faq to upload a file.


I agree. I assumed that pathinfo simply returned the relative or 
absolute path of the file. After further inspection I have to stand 
corrected and agree that using pathinfo is the best approach. I should 
have probably done some more research when putting together my solution. 
Asking the list would've been an even better option ;-) .  Thats why 
there's no substitute for experience or better line of work because you 
learn something everyday. Thanks gentleman. Time for some refactoring.  :-D


Regards
Warren
//

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



Re: [PHP] Reg Ex

2008-11-01 Thread Ashley Sheridan
On Fri, 2008-10-31 at 15:03 +0100, Jochem Maas wrote:
> Eric Butera schreef:
> > On Fri, Oct 31, 2008 at 9:09 AM, Warren Windvogel
> > <[EMAIL PROTECTED]> wrote:
> >> Eric Butera wrote:
> >>> Who says every file will have an extension?  Who says they're all .+3
> >>> chars?  When I first started php I tried that and it failed in a lot
> >>> of places.
> >> I've also run into that problem in the past. The way that I could work
> >> around all these issues was to document naming conventions for the files 
> >> and
> >> validate these before using the regex to obtain the necessary information.
> >>
> >> Regards
> >> Warren
> >>
> > 
> > ...or you could just use pathinfo and be done with it.  I work for
> > clients.  Clients shouldn't have to read a faq to upload a file.
> 
> no. they generally believe that when they upload a CSV file in a field
> very clearly marked "upload your FLASH file here" things should just work :-)
> 
> > 
> 
> 
I had exactly the same problem with someone wondering why a PDF CV
wouldnt upload in a form marked CSV upload, she adamantly refused to
read it properly!


Ash
www.ashleysheridan.co.uk


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



[PHP] Reg-ex help

2009-02-04 Thread Craige Leeder

Hey guys,

I'm trying to write a regular expression to match a tag for my 
frameworks template engine.  I seem to be having some trouble.  The 
expression should match:


{:seg 'segname':}
{:seg 'segname' cache:}

What I have is...

$fSegRegEx = "#\{:seg \'[a-z0-9\-\_]{3,}\'( cache)?:\}#i";

Which when run against my test data, seems to match:

"{:seg 'segname' cache:}"
" cache"





For arguments sake, I'll provide the whole code snippet...

   preg_match($fSegRegEx, $this->msOpCont, $faSegMatches);

   /* faSegMatches ==

* array

* 0 => '{:seg 'users_online' cache:}'//

* 1 => ' cache'//

*/

 while ( $fMatch = current($faSegMatches) ) {

   /* 


* Expected:

* $fMatch[0] = "{:seg "

* $fMatch[1] = Segment Name

* 


* $fMatch[2] = " cache:}"

* or

* $fMatch[2] = " :}"

*/

   $faMatch  = explode("'", $fMatch);

   //...

   //...

   next($faSegMatches);

 }// End While


Thanks guys.  This has been bugging me for a couple days.
- Craige


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



[PHP] reg ex help

2005-11-04 Thread conditional motion
New to php so please bear with me.  I'm trying to parse through a
field that has some information in it, the information is stored with
other information and is delimited in a certain pattern so I figure
using reg ex I can get the information I want out of the text.

So here is an example.

Silver Small Corp;X^%\n#\n
Gold Medium Corp;RE^%\n#\n
Platinum Large Corp;YRE^%\n#\n

Reall all I need is the information on Silver Small Corp, etc and the
X all the rest is gibberish.  Is Reg Ex the best way to do this or
would it be some other way.

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



Re: [PHP] reg-ex problem

2001-02-07 Thread CC Zona

In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] 
(Lee Stretton) wrote:



>   elseif( preg_match( "/^[a-zA-Z]+$/", $arg[$i], $matches ) )



>   elseif( preg_match( "/(div\d|prem)/", $arg[$i], $matches ) )



> The first 3 work fine, but the last one "/(div\d|prem)/" doesnt work
> properly. It does work if I have say div1, but if I have prem it doesnt
> work at all. I have tried changing the regex so it only contains
> "/prem/" and it still doesnt work. can anyone tell me what is wrong with
> this code, or is it just a bug in my version of php?

Your earlier test for "/^[a-zA-Z]+$/" catches any string that is all 
letters from beginning to end.  Thus a string == "prem" would be caught 
above, and never reach the test for "/(div\d|prem)/".

-- 
CC

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] reg-ex problem

2001-02-07 Thread Michael Dearman



> }
> elseif( preg_match( "/^\d+$/", $arg[$i], $matches ) )

Isn't this \d+ matching --^
> {
> $value = $matches[0];
> }
> elseif( preg_match( "/(div\d|prem)/", $arg[$i], $matches ) )

the \d in this-^^

And the | is using '\d' and 'prem'. It probably should be "/(div\d)|prem/
Unless those parens are part of the expression. Then maybe "/\((div\d)|prem\)/"
MD

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] reg-ex problem

2001-02-07 Thread Christian Reiniger

On Wednesday 07 February 2001 21:50, Michael Dearman wrote:
> > }
> > elseif( preg_match( "/^\d+$/", $arg[$i], $matches ) )
>
> Isn't this \d+ matching --^
>
> > {
> > $value = $matches[0];
> > }
> > elseif( preg_match( "/(div\d|prem)/", $arg[$i], $matches ) )
>
> the \d in this-^^

No. the 1st expression is /^\d+$/ , i.e. match strings with at least one 
decimal number and nothing else (\d+) from their beginning (^) to their 
end ($)
I.e. that one only catches strings consisting only of decimal digits.

> And the | is using '\d' and 'prem'. It probably should be
> "/(div\d)|prem/ Unless those parens are part of the expression. Then

No, that's fine.
(div\d|prem)

means "match either 'div\d' or 'prem'" and memorize that part

-- 
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)

"These are the people who proudly call themselves "hackers" --
not as the term is now abused by journalists to mean a computer
criminal, but in its true and original sense of an enthusiast,
an artist, a tinkerer, a problem solver, an expert."

- ESR

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] reg-ex problem

2001-02-07 Thread Michael Dearman


Christian Reiniger wrote:
> 
> On Wednesday 07 February 2001 21:50, Michael Dearman wrote:
> > > }
> > > elseif( preg_match( "/^\d+$/", $arg[$i], $matches ) )
> >
> > Isn't this \d+ matching --^
> >
> > > {
> > > $value = $matches[0];
> > > }
> > > elseif( preg_match( "/(div\d|prem)/", $arg[$i], $matches ) )
> >
> > the \d in this-^^
> 
> No. the 1st expression is /^\d+$/ , i.e. match strings with at least one
> decimal number and nothing else (\d+) from their beginning (^) to their
> end ($)
> I.e. that one only catches strings consisting only of decimal digits.

That's what I get for shooting my mouth off without actually trying it out.
But I should of caught the ^$ 

> 
> > And the | is using '\d' and 'prem'. It probably should be
> > "/(div\d)|prem/ Unless those parens are part of the expression. Then

And after a second look, yea the \d is tightly bound to the div.
But in confirming this, besides matching something like
'div2' it will also match div23 - both returning div2. 
Don't know the data, so it might not make any difference.

Mike D.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] reg-ex problem

2001-02-08 Thread Christian Reiniger

On Thursday 08 February 2001 07:40, Michael Dearman wrote:
> > > And the | is using '\d' and 'prem'. It probably should be
> > > "/(div\d)|prem/ Unless those parens are part of the expression.
> > > Then
>
> And after a second look, yea the \d is tightly bound to the div.
> But in confirming this, besides matching something like
> 'div2' it will also match div23 - both returning div2.

Well, it matches on "div2", no matter what's around that. just like 
"prem" also matches on "appremoval"

> Don't know the data, so it might not make any difference.

Agreed 

-- 
Christian Reiniger
LGDC Webmaster (http://sunsite.dk/lgdc/)

The use of COBOL cripples the mind; its teaching should, therefore,
be regarded as a criminal offence.

- Edsger W. Dijkstra

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




AW: [PHP] reg-ex please

2002-04-27 Thread Red Wingate

Try it like this :
$code[$i] = ereg_replace("&#([0-9] {5});" , "\\1.bing" , $code[$i] );

-Ursprüngliche Nachricht-
Von: John Fishworld [mailto:[EMAIL PROTECTED]]
Gesendet: Samstag, 27. April 2002 1:11 PM
An: [EMAIL PROTECTED]
Betreff: [PHP] reg-ex please

Help please from one of the reg-ex experts out there please !

I'm trying to find the pattern &#(5 number);
example 𑃸

This works
$code[$i] = ereg_replace("&#([0-9])+" , "replace\\0.bing" , $code[$i] );

and I get back replace 𑃸.bing

but I also want to lose the &# and the ;
so I get back 69880.bing

At the moment I just re search and remove the like this
$code[$i] = ereg_replace('&#','',$code[$i]);
$code[$i] = ereg_replace(';','',$code[$i]);

but I'm sure that theortetically I can do it in one step !
Can anyone help !
Thanks in advance



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



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




AW: [PHP] reg-ex please

2002-04-27 Thread Red Wingate

Woops , one to many whitespace :)

-->
Try it like this :
$code[$i] = ereg_replace("&#([0-9]{5});" , "\\1.bing" , $code[$i] );



-Ursprüngliche Nachricht-
Von: Red Wingate [mailto:[EMAIL PROTECTED]]
Gesendet: Samstag, 27. April 2002 1:26 PM
An: [EMAIL PROTECTED]
Betreff: AW: [PHP] reg-ex please

Try it like this :
$code[$i] = ereg_replace("&#([0-9] {5});" , "\\1.bing" ,
$code[$i] );

-Ursprüngliche Nachricht-
Von: John Fishworld [mailto:[EMAIL PROTECTED]]
Gesendet: Samstag, 27. April 2002 1:11 PM
An: [EMAIL PROTECTED]
Betreff: [PHP] reg-ex please

Help please from one of the reg-ex experts out there please !

I'm trying to find the pattern &#(5 number);
example 𑃸

This works
$code[$i] = ereg_replace("&#([0-9])+" , "replace\\0.bing" , $code[$i] );

and I get back replace 𑃸.bing

but I also want to lose the &# and the ;
so I get back 69880.bing

At the moment I just re search and remove the like this
$code[$i] = ereg_replace('&#','',$code[$i]);
$code[$i] = ereg_replace(';','',$code[$i]);

but I'm sure that theortetically I can do it in one step !
Can anyone help !
Thanks in advance



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



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



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




Re: [PHP] reg-ex please

2002-04-27 Thread John Fishworld

Excellent  :-)))
Thanks !
Can I trouble you again with one more !


I get an url http://whatever/file.whatever (text/html/chtml)

Now trying to do the following get just the http://whatever bit
and go through my array and find .gif or .html or .chtml
and replace the eg "pics/my.gif" with http://whatever/pics/my.gif

I've only just started with this one so haven't got very far but you were so
quick I thought I'd ask ! :-))

This is my start but its definately wrong !

$code[$i] = ereg_replace("^.+.gif", "$url_file\\0",$code[$i]);

er...thanks ! :-))



> Woops , one to many whitespace :)
>
> -->
> Try it like this :
> $code[$i] = ereg_replace("&#([0-9]{5});" , "\\1.bing" , $code[$i] );
>
>
>
> -Ursprüngliche Nachricht-
> Von: Red Wingate [mailto:[EMAIL PROTECTED]]
> Gesendet: Samstag, 27. April 2002 1:26 PM
> An: [EMAIL PROTECTED]
> Betreff: AW: [PHP] reg-ex please
>
> Try it like this :
> $code[$i] = ereg_replace("&#([0-9] {5});" , "\\1.bing" ,
> $code[$i] );
>
> -Ursprüngliche Nachricht-
> Von: John Fishworld [mailto:[EMAIL PROTECTED]]
> Gesendet: Samstag, 27. April 2002 1:11 PM
> An: [EMAIL PROTECTED]
> Betreff: [PHP] reg-ex please
>
> Help please from one of the reg-ex experts out there please !
>
> I'm trying to find the pattern &#(5 number);
> example 𑃸
>
> This works
> $code[$i] = ereg_replace("&#([0-9])+" , "replace\\0.bing" , $code[$i] );
>
> and I get back replace 𑃸.bing
>
> but I also want to lose the &# and the ;
> so I get back 69880.bing
>
> At the moment I just re search and remove the like this
> $code[$i] = ereg_replace('&#','',$code[$i]);
> $code[$i] = ereg_replace(';','',$code[$i]);
>
> but I'm sure that theortetically I can do it in one step !
> Can anyone help !
> Thanks in advance
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



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




AW: [PHP] reg-ex please

2002-04-27 Thread Red Wingate

Sure :)

-Ursprüngliche Nachricht-
Von: John Fishworld [mailto:[EMAIL PROTECTED]]
Gesendet: Samstag, 27. April 2002 1:46 PM
An: Red Wingate; [EMAIL PROTECTED]
Betreff: Re: [PHP] reg-ex please

Excellent  :-)))
Thanks !
Can I trouble you again with one more !


I get an url http://whatever/file.whatever (text/html/chtml)

Now trying to do the following get just the http://whatever bit
and go through my array and find .gif or .html or .chtml
and replace the eg "pics/my.gif" with http://whatever/pics/my.gif

I've only just started with this one so haven't got very far but you were so
quick I thought I'd ask ! :-))

This is my start but its definately wrong !

$code[$i] = ereg_replace("^.+.gif", "$url_file\\0",$code[$i]);

er...thanks ! :-))



> Woops , one to many whitespace :)
>
> -->
> Try it like this :
> $code[$i] = ereg_replace("&#([0-9]{5});" , "\\1.bing" , $code[$i] );
>
>
>
> -Ursprüngliche Nachricht-
> Von: Red Wingate [mailto:[EMAIL PROTECTED]]
> Gesendet: Samstag, 27. April 2002 1:26 PM
> An: [EMAIL PROTECTED]
> Betreff: AW: [PHP] reg-ex please
>
> Try it like this :
> $code[$i] = ereg_replace("&#([0-9] {5});" , "\\1.bing" ,
> $code[$i] );
>
> -Ursprüngliche Nachricht-
> Von: John Fishworld [mailto:[EMAIL PROTECTED]]
> Gesendet: Samstag, 27. April 2002 1:11 PM
> An: [EMAIL PROTECTED]
> Betreff: [PHP] reg-ex please
>
> Help please from one of the reg-ex experts out there please !
>
> I'm trying to find the pattern &#(5 number);
> example 𑃸
>
> This works
> $code[$i] = ereg_replace("&#([0-9])+" , "replace\\0.bing" , $code[$i] );
>
> and I get back replace 𑃸.bing
>
> but I also want to lose the &# and the ;
> so I get back 69880.bing
>
> At the moment I just re search and remove the like this
> $code[$i] = ereg_replace('&#','',$code[$i]);
> $code[$i] = ereg_replace(';','',$code[$i]);
>
> but I'm sure that theortetically I can do it in one step !
> Can anyone help !
> Thanks in advance
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>



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



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




Re: [PHP] reg-ex again

2002-04-29 Thread Jason Wong

On Monday 29 April 2002 15:22, John Fishworld wrote:
> I'm trying to find files in my array
> for example
> ="lg_imode.gif"
> and
> ="/db/imodeklein/edgar-IMODE-1-.gif"
>
> I want to differentiate between the files with slash at the front and ones
> without so that
> I can add a server path !
> but as usual I' m having problems with the correct regex

Assuming that all those files which have a '/' at the front already have a 
valid path, and thus it is only those without a '/' that needs a path, then 
wouldn't it be far simpler to just check the first character to see whether 
it is a '/' and act accordingly? 

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
<< WAIT >>
*/

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




Re[2]: [PHP] Reg Ex

2008-11-10 Thread ANR Daemon
Greetings, "Boyd, Todd M.".
In reply to Your message dated Friday, October 31, 2008, 17:51:59,

> Someone suggested pathinfo() already... and brought up the issues of
> extensions < 3 chars and files with no "basename" (i.e., ".htaccess")...

> Checked out www.php.net/pathinfo, and ran a demo on my own machine. I
> can't test the .htaccess problem, since I'm running Windows (and M$
> won't let you have files that start with "."), but I tested it with
> "a.b.c.d" and the extension was returned as "d". Basename was "a.b.c".

M$ permissions has nothing to do with your problem.
Notepad - File - Save as - .htaccess, File type: All files

Here you got it.
But it's easier to use more straight tools than stupid explorer.

> Sounds like it will do exactly what you are trying to accomplish. For
> what it's worth, if I were to do it with a regular expression, I would
> use:

> $filename = "us.123.kyle.20081029.zip";
> preg_match('/(.*)\..*$/', $filename, $match);

I should correct you to
#^((.+)(\.[^\.]+)?)$#
Results will be
 1 => Filename
 2 => Basename
 3 => Extension


-- 
Sincerely Yours, ANR Daemon <[EMAIL PROTECTED]>


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



Re[2]: [PHP] Reg Ex

2008-11-10 Thread ANR Daemon
Greetings, "Diogo Neves".
In reply to Your message dated Friday, October 31, 2008, 20:08:25,

> It depends on what he really want, but pathinfo really is a better option

> My test worked perfectly on files with no extension and without name...

File always have name. Extension is a part of it.

>  var_dump( pathinfo( '.htaccess' ));
> var_dump( pathinfo( 'htaccess' ));
> die( );
> ?>



-- 
Sincerely Yours, ANR Daemon <[EMAIL PROTECTED]>


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



Re: [PHP] Reg-ex help

2009-02-04 Thread Jim Lucas

Craige Leeder wrote:

Hey guys,

I'm trying to write a regular expression to match a tag for my 
frameworks template engine.  I seem to be having some trouble.  The 
expression should match:


{:seg 'segname':}
{:seg 'segname' cache:}

What I have is...

$fSegRegEx = "#\{:seg \'[a-z0-9\-\_]{3,}\'( cache)?:\}#i";

Which when run against my test data, seems to match:

"{:seg 'segname' cache:}"
" cache"


Thanks guys.  This has been bugging me for a couple days.
- Craige




I used some of your code, but try this variant on for size.




{:seg 'title':}
{:seg 'title' cache:}



DATA;

# For arguments sake, I'll provide the whole code snippet...

$fSegRegEx = "|\{:(seg) \'([a-z0-9\-\_]{3,})\'\s?(cache)?:\}|i";

preg_match_all($fSegRegEx, $dummyData, $faSegMatches, PREG_SET_ORDER);
print_r($faSegMatches);

?>

Not sure what your input is going to be (HTML, XML, etc...) so I used HTML

Anyways, output from the above code is this:



Array
(
[0] => Array
(
[0] => {:seg 'title':}
[1] => seg
[2] => title
)

[1] => Array
(
[0] => {:seg 'title' cache:}
[1] => seg
[2] => title
[3] => cache
)

)

Hope this starts you down the right path.

--
Jim Lucas

   "Some men are born to greatness, some achieve greatness,
   and some have greatness thrust upon them."

Twelfth Night, Act II, Scene V
by William Shakespeare


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



Re: [PHP] Reg-ex help

2009-02-05 Thread Jochem Maas
Craige Leeder schreef:
> Hey guys,
> 
> I'm trying to write a regular expression to match a tag for my
> frameworks template engine.  I seem to be having some trouble.  The
> expression should match:
> 
> {:seg 'segname':}
> {:seg 'segname' cache:}
> 
> What I have is...
> 
> $fSegRegEx = "#\{:seg \'[a-z0-9\-\_]{3,}\'( cache)?:\}#i";

hth:



{:seg 'title':}
{:seg 'title' cache:}



DATA;


preg_match_all($fSegRegEx, $str, $faSegMatches, PREG_SET_ORDER);
print_r($faSegMatches);

?>

OUTPUTS:

Array
(
[0] => Array
(
[0] => {:seg 'title':}
[1] => {:seg
[2] => title
[3] => :}
)

[1] => Array
(
[0] => {:seg 'title' cache:}
[1] => {:seg
[2] => title
[3] =>  cache:}
)

)


> 
> Which when run against my test data, seems to match:
> 
> "{:seg 'segname' cache:}"
> " cache"
> 
> 
> 
> 
> 
> For arguments sake, I'll provide the whole code snippet...
> 
>preg_match($fSegRegEx, $this->msOpCont, $faSegMatches);
> 
>/* faSegMatches ==
> 
> * array
> 
> * 0 => '{:seg 'users_online' cache:}'//
> 
> * 1 => ' cache'//
> 
> */
> 
>  while ( $fMatch = current($faSegMatches) ) {
> 
>/*
> * Expected:
> 
> * $fMatch[0] = "{:seg "
> 
> * $fMatch[1] = Segment Name
> 
> *
> * $fMatch[2] = " cache:}"
> 
> * or
> 
> * $fMatch[2] = " :}"
> 
> */
> 
>$faMatch  = explode("'", $fMatch);
> 
>//...
> 
>//...
> 
>next($faSegMatches);
> 
>  }// End While
> 
> 
> Thanks guys.  This has been bugging me for a couple days.
> - Craige
> 
> 


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



Re: [PHP] Reg-ex help

2009-02-07 Thread Craige Leeder

Thanks!

That's a big help.

- Craige

Jim Lucas wrote:

Craige Leeder wrote:

Hey guys,

I'm trying to write a regular expression to match a tag for my 
frameworks template engine.  I seem to be having some trouble.  The 
expression should match:


{:seg 'segname':}
{:seg 'segname' cache:}

What I have is...

$fSegRegEx = "#\{:seg \'[a-z0-9\-\_]{3,}\'( cache)?:\}#i";

Which when run against my test data, seems to match:

"{:seg 'segname' cache:}"
" cache"


Thanks guys.  This has been bugging me for a couple days.
- Craige




I used some of your code, but try this variant on for size.




{:seg 'title':}
{:seg 'title' cache:}



DATA;

# For arguments sake, I'll provide the whole code snippet...

$fSegRegEx = "|\{:(seg) \'([a-z0-9\-\_]{3,})\'\s?(cache)?:\}|i";

preg_match_all($fSegRegEx, $dummyData, $faSegMatches, PREG_SET_ORDER);
print_r($faSegMatches);

?>

Not sure what your input is going to be (HTML, XML, etc...) so I used 
HTML


Anyways, output from the above code is this:



Array
(
[0] => Array
(
[0] => {:seg 'title':}
[1] => seg
[2] => title
)

[1] => Array
(
[0] => {:seg 'title' cache:}
[1] => seg
[2] => title
[3] => cache
)

)

Hope this starts you down the right path.



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



RE: [PHP] reg ex help

2005-11-04 Thread Jay Blanchard
[snip]
New to php so please bear with me.  I'm trying to parse through a
field that has some information in it, the information is stored with
other information and is delimited in a certain pattern so I figure
using reg ex I can get the information I want out of the text.

So here is an example.

Silver Small Corp;X^%\n#\n
Gold Medium Corp;RE^%\n#\n
Platinum Large Corp;YRE^%\n#\n

Reall all I need is the information on Silver Small Corp, etc and the
X all the rest is gibberish.  Is Reg Ex the best way to do this or
would it be some other way.
[/snip]

You couuld use explode

$myField = "Silver Small Corp;X^%\n#\n";

$foo = explode(";", $myField);

echo $foo[0];

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



Re: [PHP] reg ex help

2005-11-04 Thread conditional motion
The problem with that is there are about 40 different listings in the
one field.

Silver Small Corp;X^%\n#\n
Gold Medium Corp;RE^%\n#\n
Platinum Large Corp;YRE^%\n#\n

being three of them so maybe this is a bettter way of listing it

... Silver Small Corp;X^%\n#\nGold Medium
Corp;RE^%\n#\nPlatinum Large Corp;YRE^%\n#\n
...

On 11/4/05, Jay Blanchard <[EMAIL PROTECTED]> wrote:
> [snip]
> New to php so please bear with me.  I'm trying to parse through a
> field that has some information in it, the information is stored with
> other information and is delimited in a certain pattern so I figure
> using reg ex I can get the information I want out of the text.
>
> So here is an example.
>
> Silver Small Corp;X^%\n#\n
> Gold Medium Corp;RE^%\n#\n
> Platinum Large Corp;YRE^%\n#\n
>
> Reall all I need is the information on Silver Small Corp, etc and the
> X all the rest is gibberish.  Is Reg Ex the best way to do this or
> would it be some other way.
> [/snip]
>
> You couuld use explode
>
> $myField = "Silver Small Corp;X^%\n#\n";
>
> $foo = explode(";", $myField);
>
> echo $foo[0];
>

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



RE: [PHP] reg ex help

2005-11-04 Thread Pablo Gosse
[snip]
New to php so please bear with me.  I'm trying to parse through a field
that has some information in it, the information is stored with other
information and is delimited in a certain pattern so I figure using reg
ex I can get the information I want out of the text.

So here is an example.

Silver Small Corp;X^%\n#\n
Gold Medium Corp;RE^%\n#\n
Platinum Large Corp;YRE^%\n#\n

Reall all I need is the information on Silver Small Corp, etc and the X
all the rest is gibberish.  Is Reg Ex the best way to do this or would
it be some other way.[/snip]

If the number of semi-colons is fixed, then explode will do the trick.

$foo = 'Silver Small Corp;X^%\n#\n'; $bar = explode(';',
$foo); echo $bar[0];

However if the number of semi-colons is not fixed, then substr in
conjunction with strpos will do the trick.

$foo = 'Silver Small Corp;X^%\n#\n'; $bar = substr($foo, 0,
strpos($foo, ';')); echo $bar;

HTH,

Pablo

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



RE: [PHP] reg ex help

2005-11-04 Thread Pablo Gosse
[snip]
The problem with that is there are about 40 different listings in the
one field.

Silver Small Corp;X^%\n#\n
Gold Medium Corp;RE^%\n#\n
Platinum Large Corp;YRE^%\n#\n

being three of them so maybe this is a bettter way of listing it

... Silver Small Corp;X^%\n#\nGold Medium
Corp;RE^%\n#\nPlatinum Large Corp;YRE^%\n#\n
...[/snip]

Try this:

$values = array(); // we'll put the extracted vars here
$str = "This is supposed to be your string";

$tmpStr = explode("#\n", $str);

foreach ($tmpStr as $foo) {
if (strlen(trim($foo)) > 0) {
array_push($values, substr($foo, 0, strpos($foo, ';')));

}
}

HTH,

Pablo

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



Re: [PHP] reg ex help

2005-11-04 Thread conditional motion
Here is what the field content from the database would look like.  I
have removed any sensitive data.

str = "Name;Grill Transom (GT302)^% -
Sort;Find/Replace^% - Calc;2568.09x^% -
Type;Veck^% - PO Number;^% - Previous Order
Number;^% - Fabric Whole;Dyna-Dry^% - Fabric
Body;^% - Fabric Yoke;^% - Fabric
Sleeves;^% - Fabric Panels;^% -
ID;32398^%^%^%^%^% -
Size;6.0^%^%^%^%^% -
Layer;0^%^%^%^%^% -
Coords;147^173^400^%^^^%^^^%^^^%^^^%
- ID;%32400^%^%%%^%
- 
Coords;%147^110^400^%^^^%%%^^^%
- Back Number
Font;%Athletic^Athletic^%
- Front Text
ID;%%32402^%32403^%^%^%^%^%^%
- Roch Small Sum;0^% - Cards Med Extra;0^%
- Roch Large Sum;0^% - Silver Small Corp;X^%
- Gold Medium Corp;RE^% - Platinum Large
Corp;YRE^%";

That is one field.

On 11/4/05, Pablo Gosse <[EMAIL PROTECTED]> wrote:
> [snip]
> The problem with that is there are about 40 different listings in the
> one field.
>
> Silver Small Corp;X^%\n#\n
> Gold Medium Corp;RE^%\n#\n
> Platinum Large Corp;YRE^%\n#\n
>
> being three of them so maybe this is a bettter way of listing it
>
> ... Silver Small Corp;X^%\n#\nGold Medium
> Corp;RE^%\n#\nPlatinum Large Corp;YRE^%\n#\n
> ...[/snip]
>
> Try this:
>
> $values = array(); // we'll put the extracted vars here
> $str = "This is supposed to be your string";
>
> $tmpStr = explode("#\n", $str);
>
> foreach ($tmpStr as $foo) {
>if (strlen(trim($foo)) > 0) {
>array_push($values, substr($foo, 0, strpos($foo, ';')));
>
>}
> }
>
> HTH,
>
> Pablo
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

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



Re: [PHP] reg ex help

2005-11-04 Thread conditional motion
The name like "Roch Small Sum" and others dont change, they will be in
there whether there is a value associated with them or not.


On 11/4/05, conditional motion <[EMAIL PROTECTED]> wrote:
> Here is what the field content from the database would look like.  I
> have removed any sensitive data.
>
> str = "Name;Grill Transom (GT302)^% -
> Sort;Find/Replace^% - Calc;2568.09x^% -
> Type;Veck^% - PO Number;^% - Previous Order
> Number;^% - Fabric Whole;Dyna-Dry^% - Fabric
> Body;^% - Fabric Yoke;^% - Fabric
> Sleeves;^% - Fabric Panels;^% -
> ID;32398^%^%^%^%^% -
> Size;6.0^%^%^%^%^% -
> Layer;0^%^%^%^%^% -
> Coords;147^173^400^%^^^%^^^%^^^%^^^%
> - ID;%32400^%^%%%^%
> - 
> Coords;%147^110^400^%^^^%%%^^^%
> - Back Number
> Font;%Athletic^Athletic^%
> - Front Text
> ID;%%32402^%32403^%^%^%^%^%^%
> - Roch Small Sum;0^% - Cards Med Extra;0^%
> - Roch Large Sum;0^% - Silver Small Corp;X^%
> - Gold Medium Corp;RE^% - Platinum Large
> Corp;YRE^%";
>
> That is one field.
>
> On 11/4/05, Pablo Gosse <[EMAIL PROTECTED]> wrote:
> > [snip]
> > The problem with that is there are about 40 different listings in the
> > one field.
> >
> > Silver Small Corp;X^%\n#\n
> > Gold Medium Corp;RE^%\n#\n
> > Platinum Large Corp;YRE^%\n#\n
> >
> > being three of them so maybe this is a bettter way of listing it
> >
> > ... Silver Small Corp;X^%\n#\nGold Medium
> > Corp;RE^%\n#\nPlatinum Large Corp;YRE^%\n#\n
> > ...[/snip]
> >
> > Try this:
> >
> > $values = array(); // we'll put the extracted vars here
> > $str = "This is supposed to be your string";
> >
> > $tmpStr = explode("#\n", $str);
> >
> > foreach ($tmpStr as $foo) {
> >if (strlen(trim($foo)) > 0) {
> >array_push($values, substr($foo, 0, strpos($foo, ';')));
> >
> >}
> > }
> >
> > HTH,
> >
> > Pablo
> >
> > --
> > PHP General Mailing List (http://www.php.net/)
> > To unsubscribe, visit: http://www.php.net/unsub.php
> >
> >
>

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



Re: [PHP] reg ex help

2005-11-04 Thread Dan McCullough
Whos responsible for putting all that information into one field.  LOL

On 11/4/05, conditional motion <[EMAIL PROTECTED]> wrote:
> The name like "Roch Small Sum" and others dont change, they will be in
> there whether there is a value associated with them or not.
>
>
> On 11/4/05, conditional motion <[EMAIL PROTECTED]> wrote:
> > Here is what the field content from the database would look like.  I
> > have removed any sensitive data.
> >
> > str = "Name;Grill Transom (GT302)^% -
> > Sort;Find/Replace^% - Calc;2568.09x^% -
> > Type;Veck^% - PO Number;^% - Previous Order
> > Number;^% - Fabric Whole;Dyna-Dry^% - Fabric
> > Body;^% - Fabric Yoke;^% - Fabric
> > Sleeves;^% - Fabric Panels;^% -
> > ID;32398^%^%^%^%^% -
> > Size;6.0^%^%^%^%^% -
> > Layer;0^%^%^%^%^% -
> > Coords;147^173^400^%^^^%^^^%^^^%^^^%
> > - ID;%32400^%^%%%^%
> > - 
> > Coords;%147^110^400^%^^^%%%^^^%
> > - Back Number
> > Font;%Athletic^Athletic^%
> > - Front Text
> > ID;%%32402^%32403^%^%^%^%^%^%
> > - Roch Small Sum;0^% - Cards Med Extra;0^%
> > - Roch Large Sum;0^% - Silver Small Corp;X^%
> > - Gold Medium Corp;RE^% - Platinum Large
> > Corp;YRE^%";
> >
> > That is one field.
> >
> > On 11/4/05, Pablo Gosse <[EMAIL PROTECTED]> wrote:
> > > [snip]
> > > The problem with that is there are about 40 different listings in the
> > > one field.
> > >
> > > Silver Small Corp;X^%\n#\n
> > > Gold Medium Corp;RE^%\n#\n
> > > Platinum Large Corp;YRE^%\n#\n
> > >
> > > being three of them so maybe this is a bettter way of listing it
> > >
> > > ... Silver Small Corp;X^%\n#\nGold Medium
> > > Corp;RE^%\n#\nPlatinum Large Corp;YRE^%\n#\n
> > > ...[/snip]
> > >
> > > Try this:
> > >
> > > $values = array(); // we'll put the extracted vars here
> > > $str = "This is supposed to be your string";
> > >
> > > $tmpStr = explode("#\n", $str);
> > >
> > > foreach ($tmpStr as $foo) {
> > >if (strlen(trim($foo)) > 0) {
> > >array_push($values, substr($foo, 0, strpos($foo, ';')));
> > >
> > >}
> > > }
> > >
> > > HTH,
> > >
> > > Pablo
> > >
> > > --
> > > PHP General Mailing List (http://www.php.net/)
> > > To unsubscribe, visit: http://www.php.net/unsub.php
> > >
> > >
> >
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

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



Re: [PHP] reg ex help

2005-11-04 Thread Jochem Maas

explode on this first: '^% -'

then probably on explode ';' like Jay mentioned.

then you can probably massage the really weird stuff into shape
somehow, stuff like (wtf :-)):
Back Number 
Font;%Athletic^Athletic

..hth

conditional motion wrote:

The name like "Roch Small Sum" and others dont change, they will be in
there whether there is a value associated with them or not.


On 11/4/05, conditional motion <[EMAIL PROTECTED]> wrote:


Here is what the field content from the database would look like.  I
have removed any sensitive data.

str = "Name;Grill Transom (GT302)^% -
Sort;Find/Replace^% - Calc;2568.09x^% -
Type;Veck^% - PO Number;^% - Previous Order
Number;^% - Fabric Whole;Dyna-Dry^% - Fabric
Body;^% - Fabric Yoke;^% - Fabric
Sleeves;^% - Fabric Panels;^% -
ID;32398^%^%^%^%^% -
Size;6.0^%^%^%^%^% -
Layer;0^%^%^%^%^% -
Coords;147^173^400^%^^^%^^^%^^^%^^^%
- ID;%32400^%^%%%^%
- 
Coords;%147^110^400^%^^^%%%^^^%
- Back Number
Font;%Athletic^Athletic^%
- Front Text
ID;%%32402^%32403^%^%^%^%^%^%
- Roch Small Sum;0^% - Cards Med Extra;0^%
- Roch Large Sum;0^% - Silver Small Corp;X^%
- Gold Medium Corp;RE^% - Platinum Large
Corp;YRE^%";

That is one field.

On 11/4/05, Pablo Gosse <[EMAIL PROTECTED]> wrote:


[snip]
The problem with that is there are about 40 different listings in the
one field.

Silver Small Corp;X^%\n#\n
Gold Medium Corp;RE^%\n#\n
Platinum Large Corp;YRE^%\n#\n

being three of them so maybe this is a bettter way of listing it

... Silver Small Corp;X^%\n#\nGold Medium
Corp;RE^%\n#\nPlatinum Large Corp;YRE^%\n#\n
...[/snip]

Try this:

$values = array(); // we'll put the extracted vars here
$str = "This is supposed to be your string";

$tmpStr = explode("#\n", $str);

foreach ($tmpStr as $foo) {
  if (strlen(trim($foo)) > 0) {
  array_push($values, substr($foo, 0, strpos($foo, ';')));

  }
}

HTH,

Pablo

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








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



Re: [PHP] reg ex help

2005-11-04 Thread Curt Zirzow
On Fri, 04 Nov 2005 14:09:06 -0500, conditional motion wrote:

> Here is what the field content from the database would look like.  I have
> removed any sensitive data.
> 
> str = "Name;Grill Transom (GT302)^% -
> Sort;Find/Replace^% - Calc;2568.09x^% -
> Type;Veck^% - PO Number;^% - Previous Order
> Number;^% - Fabric Whole;Dyna-Dry^% - Fabric
> ...

If you really want a regex.. something like:

  preg_match_all('/\s*([^;]+);{5}([^^]*)^/U', $str, $matches);
  var_dump($matches);

And you'll have an array of field => values (excuding the Coords field).


I do wonder why this is stored in the db like this.

Curt.
-- 
http://news.zirzow.dyndns.org/

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



Re: [PHP] reg ex help

2005-11-08 Thread Richard Lynch
On Fri, November 4, 2005 12:09 pm, conditional motion wrote:
> New to php so please bear with me.  I'm trying to parse through a
> field that has some information in it, the information is stored with
> other information and is delimited in a certain pattern so I figure
> using reg ex I can get the information I want out of the text.
>
> So here is an example.
>
> Silver Small Corp;X^%\n#\n
> Gold Medium Corp;RE^%\n#\n
> Platinum Large Corp;YRE^%\n#\n
>
> Reall all I need is the information on Silver Small Corp, etc and the
> X all the rest is gibberish.  Is Reg Ex the best way to do this or
> would it be some other way.

Try this (untested):


The 'm' at the end might need to be an 's', but I think 'm' is right.

-- 
Like Music?
http://l-i-e.com/artists.htm

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



[PHP] Reg Ex for replacing or with \n

2002-12-27 Thread Tom Beddard
I'm new to using regular expressions so i'm struggling a bit in making an
expression to replace  or  with \n

$string = preg_replace( "/(|)/i" , "\n",$string);

which needless to say doesn't work. I'm sure its obvious, just need a bit of
a pointer!

Cheers
Tom



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




[PHP] Reg ex help-Removing extra blank spaces before HTML output

2001-12-04 Thread Ken

I want to remove all superfluous blank spaces before I sent my HTML output, to make 
the output smaller.

So I'd like to take $input, replace any number of blank space or newlines that are 
consecutive and replace them with a single blank.

I.e. I will list a blank space as b and a newline as n:

If input is: bTEXTHEREbbbnnnbnMOREbEVENMORE
Then output should be: bTEXTHEREbMOREbEVENMORE

I imagine this would be handled by a simple regular expression call, but I'm no pro 
with them yet.

Any help?

Thanks,
Ken
[EMAIL PROTECTED]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Reg ex help-Removing extra blank spaces before HTMLoutput

2001-12-04 Thread Steve Edberg

One way to do it is:

$NewString = ereg_replace('[[:space:]]+', ' ', $String);

There are also ways to do it with preg functions that are slightly 
more efficient; see the pcre docs. And, the standard (AFAIK) 
reference book for regular expressions is O'Reilly's 'Mastering 
Regular Expressions'; a worthwhile purchase.

-steve


At 2:06 AM -0500 12/5/01, Ken wrote:
>I want to remove all superfluous blank spaces before I sent my HTML 
>output, to make the output smaller.
>
>So I'd like to take $input, replace any number of blank space or 
>newlines that are consecutive and replace them with a single blank.
>
>I.e. I will list a blank space as b and a newline as n:
>
>If input is: bTEXTHEREbbbnnnbnMOREbEVENMORE
>Then output should be: bTEXTHEREbMOREbEVENMORE
>
>I imagine this would be handled by a simple regular expression call, 
>but I'm no pro with them yet.
>
>Any help?
>
>Thanks,
>Ken
>[EMAIL PROTECTED]
>


-- 
++
| Steve Edberg  [EMAIL PROTECTED] |
| University of California, Davis  (530)754-9127 |
| Programming/Database/SysAdmin   http://pgfsun.ucdavis.edu/ |
++
| "Restriction of free thought and free speech is the most dangerous of  |
| all subversions. It is the one un-American act that could most easily  |
| defeat us."|
| - Supreme Court Justice (1939-1975) William O. Douglas |
++

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Reg ex help-Removing extra blank spaces before HTML output

2001-12-06 Thread Ken

At 02:43 PM 12/5/01 -0500, Jack Dempsey wrote:
>$t = preg_replace('/\s+/',' ',$text);

One more thing:
How do I replace with newline instead of a space?  I read through the manuals but 
couldn't grasp how to do this.  \n didn't cut it.

And, more advanced - 
The above replaces any groups of 2 or more blanks (newlines, spaces, tabs) with a 
single blank.
Is there an easy way to replace them with EITHER a space or a newline, depending on 
whether any newlines were present in the input?
I.e. bb would be replaced with b, but bnbn would be replaced 
with n.

Right now the issue is that I'm sometimes getting results that have no line breaks for 
a really long time, and I know there are reasons to try to avoid individual lines of 
HTML longer than 200 characters.

Thanks!

- Ken
[EMAIL PROTECTED]


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Reg ex help-Removing extra blank spaces before HTML output

2001-12-06 Thread Jack Dempsey

using "\n" as your replacement text will do ithowever, if you want a
newline in the html, then you'll want ...

and as far as the advanced replace, make an array of search patterns, in
this case two.
your first pattern will be "/[ ]+\n+[ ]+/" with a replacement of a single
newline...then the second will be the previous regex.check out php.net
for help with syntax and using arrays with preg_* functionsthe first
should catch all situations of a series of spaces [with at least one newline
in between them] and substitute a newline.
check out mastering regular expressions as well.its worth the money
jack

-Original Message-
From: Ken [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 06, 2001 3:08 AM
To: Jack Dempsey; liljim; PHP list
Subject: RE: [PHP] Reg ex help-Removing extra blank spaces before HTML
output


At 02:43 PM 12/5/01 -0500, Jack Dempsey wrote:
>$t = preg_replace('/\s+/',' ',$text);

One more thing:
How do I replace with newline instead of a space?  I read through the
manuals but couldn't grasp how to do this.  \n didn't cut it.

And, more advanced -
The above replaces any groups of 2 or more blanks (newlines, spaces, tabs)
with a single blank.
Is there an easy way to replace them with EITHER a space or a newline,
depending on whether any newlines were present in the input?
I.e. bb would be replaced with b, but bnbn would be
replaced with n.

Right now the issue is that I'm sometimes getting results that have no line
breaks for a really long time, and I know there are reasons to try to avoid
individual lines of HTML longer than 200 characters.

Thanks!

- Ken
[EMAIL PROTECTED]


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Reg ex help-Removing extra blank spaces before HTML output

2001-12-06 Thread Jack Dempsey

second issue first:
one call to preg_replace...if you check out php.net/preg_replace, you'll see
what i mean...use arrays...
and as long as you have them ordered in the right way, it'll execute them in
that order, so by the time the \s replace comes up all your 'bbbnbb' will be
fixed...problem then is that those newlines would get caught by the \s and
get switched to spaces...so, if you want them to stay, then use [ ] to
represent a space instead of \s...might want [ \t] to catch tabs as well...
first issue: hard to see whats going on, but check your syntax. i just ran
this;
$text = "this is some text with a newline in it right here \n  there it
was";
echo $text;
echo '';
echo preg_replace("/[ ]+\n+[ ]+/","\n",$text);
and it made the substitution fine.

jack

-Original Message-
From: Ken [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 06, 2001 1:56 PM
To: Jack Dempsey
Subject: RE: [PHP] Reg ex help-Removing extra blank spaces before HTML
output


At 11:41 AM 12/6/01 -0500, Jack Dempsey wrote:
>using "\n" as your replacement text will do ithowever, if you want a
>newline in the html, then you'll want ...

Using "\n" (either in single or double quotes) resulted in actual 'backslash
n' being all over my output, instead of newlines.  Hence, my inquiry.

>your first pattern will be "/[ ]+\n+[ ]+/" with a replacement of a single
>newline...then the second will be the previous regex.check out php.net
>for help with syntax and using arrays with preg_* functionsthe first
>should catch all situations of a series of spaces [with at least one
newline
>in between them] and substitute a newline.

Thanks, sounds about right.  The second pattern (which sometimes includes
getting rid of newlines) won't clobber the results of the first pattern?
And are you suggesting two separate calls to the preg* function?  It sounds
like you are, if each of the two patterns also has a unique replacement
string.

Thanks a lot!

- Ken
[EMAIL PROTECTED]

>check out mastering regular expressions as well.its worth the money
>jack
>
>-Original Message-
>From: Ken [mailto:[EMAIL PROTECTED]]
>
>At 02:43 PM 12/5/01 -0500, Jack Dempsey wrote:
> >$t = preg_replace('/\s+/',' ',$text);
>
>One more thing:
>How do I replace with newline instead of a space?  I read through the
>manuals but couldn't grasp how to do this.  \n didn't cut it.
>
>And, more advanced -
>The above replaces any groups of 2 or more blanks (newlines, spaces, tabs)
>with a single blank.
>Is there an easy way to replace them with EITHER a space or a newline,
>depending on whether any newlines were present in the input?
>I.e. bb would be replaced with b, but bnbn would be
>replaced with n.



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Reg ex help-Removing extra blank spaces before HTML output

2001-12-06 Thread Ken

OK, this time the \n worked.  The only thing I changed was using / delimiters instead 
of | delimiters in the search string.  No idea if/why that would affect anything in 
the replacement string.

Anyway, I finally came up with exactly what I wanted:
preg_replace(array("/\s*\n+\s*/", "/[ ]+/"), array("\n", " "), $input);

All padding (defined as any series of spaces, newlines and sometimes tabs) is removed 
from $input, but always leaving at least a space or a newline in its place.  If there 
were any newlines in the "padding", then a newline is left.  If there weren't, then a 
space is left.

Thanks for the help!

Ken
[EMAIL PROTECTED]

At 04:40 PM 12/6/01 -0500, Jack Dempsey wrote:
>one call to preg_replace...if you check out php.net/preg_replace, you'll see
>what i mean...use arrays...
>and as long as you have them ordered in the right way, it'll execute them in
>that order, so by the time the \s replace comes up all your 'bbbnbb' will be
>fixed...problem then is that those newlines would get caught by the \s and
>get switched to spaces...so, if you want them to stay, then use [ ] to
>represent a space instead of \s...might want [ \t] to catch tabs as well...


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Reg ex help-Removing extra blank spaces before HTML output

2001-12-06 Thread Jack Dempsey

cool, glad you got it working...if you think there's a bug with using / and
| you might want to see if you can replicate the problem, and if its really
a bug, submit it...my guess is that it was just a typo or something

jack

-Original Message-
From: Ken [mailto:[EMAIL PROTECTED]]
Sent: Thursday, December 06, 2001 5:13 PM
To: Jack Dempsey; PHP list
Subject: RE: [PHP] Reg ex help-Removing extra blank spaces before HTML
output


OK, this time the \n worked.  The only thing I changed was using /
delimiters instead of | delimiters in the search string.  No idea if/why
that would affect anything in the replacement string.

Anyway, I finally came up with exactly what I wanted:
preg_replace(array("/\s*\n+\s*/", "/[ ]+/"), array("\n", " "), $input);

All padding (defined as any series of spaces, newlines and sometimes tabs)
is removed from $input, but always leaving at least a space or a newline in
its place.  If there were any newlines in the "padding", then a newline is
left.  If there weren't, then a space is left.

Thanks for the help!

Ken
[EMAIL PROTECTED]

At 04:40 PM 12/6/01 -0500, Jack Dempsey wrote:
>one call to preg_replace...if you check out php.net/preg_replace, you'll
see
>what i mean...use arrays...
>and as long as you have them ordered in the right way, it'll execute them
in
>that order, so by the time the \s replace comes up all your 'bbbnbb' will
be
>fixed...problem then is that those newlines would get caught by the \s and
>get switched to spaces...so, if you want them to stay, then use [ ] to
>represent a space instead of \s...might want [ \t] to catch tabs as well...



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Reg ex help-Removing extra blank spaces before HTML output

2001-12-04 Thread Jack Dempsey

$text = preg_replace('|\s+|',' ',$text);


-Original Message-
From: Ken [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, December 05, 2001 2:06 AM
To: PHP list
Subject: [PHP] Reg ex help-Removing extra blank spaces before HTML
output


I want to remove all superfluous blank spaces before I sent my HTML output,
to make the output smaller.

So I'd like to take $input, replace any number of blank space or newlines
that are consecutive and replace them with a single blank.

I.e. I will list a blank space as b and a newline as n:

If input is: bTEXTHEREbbbnnnbnMOREbEVENMORE
Then output should be: bTEXTHEREbMOREbEVENMORE

I imagine this would be handled by a simple regular expression call, but I'm
no pro with them yet.

Any help?

Thanks,
Ken
[EMAIL PROTECTED]

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Reg ex help-Removing extra blank spaces before HTML output

2001-12-05 Thread liljim

Hello,

The example Jack gave you will clear up spaces well, though to get both
newlines and spaces into one:

$input = preg_replace("/([ ]|\n){1,}/", "\\1", $input);

James

"Jack Dempsey" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> $text = preg_replace('|\s+|',' ',$text);
>
>
> -Original Message-
> From: Ken [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, December 05, 2001 2:06 AM
> To: PHP list
> Subject: [PHP] Reg ex help-Removing extra blank spaces before HTML
> output
>
>
> I want to remove all superfluous blank spaces before I sent my HTML
output,
> to make the output smaller.
>
> So I'd like to take $input, replace any number of blank space or newlines
> that are consecutive and replace them with a single blank.
>
> I.e. I will list a blank space as b and a newline as n:
>
> If input is: bTEXTHEREbbbnnnbnMOREbEVENMORE
> Then output should be: bTEXTHEREbMOREbEVENMORE
>
> I imagine this would be handled by a simple regular expression call, but
I'm
> no pro with them yet.
>
> Any help?
>
> Thanks,
> Ken
> [EMAIL PROTECTED]
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Reg ex help-Removing extra blank spaces before HTML output

2001-12-05 Thread Jack Dempsey

true...he didn't mention newlines though so i left those out...also, "since
PHP 4.0.4 $n [meaning $1], being the preferred one." you also don't need
double quotes and since + means 1 or more, i'd save myself some typing
$input = preg_replace('/(\s|\n)+/',"$1",$input);
of course since you're now matching and replacing it'll take longer than a
straight substitution, although i doubt the files you're scanning are big
enough to notice

jack

-Original Message-
From: liljim [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, December 05, 2001 5:18 AM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] Reg ex help-Removing extra blank spaces before HTML
output


Hello,

The example Jack gave you will clear up spaces well, though to get both
newlines and spaces into one:

$input = preg_replace("/([ ]|\n){1,}/", "\\1", $input);

James

"Jack Dempsey" <[EMAIL PROTECTED]> wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
> $text = preg_replace('|\s+|',' ',$text);
>
>
> -----Original Message-
> From: Ken [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, December 05, 2001 2:06 AM
> To: PHP list
> Subject: [PHP] Reg ex help-Removing extra blank spaces before HTML
> output
>
>
> I want to remove all superfluous blank spaces before I sent my HTML
output,
> to make the output smaller.
>
> So I'd like to take $input, replace any number of blank space or newlines
> that are consecutive and replace them with a single blank.
>
> I.e. I will list a blank space as b and a newline as n:
>
> If input is: bTEXTHEREbbbnnnbnMOREbEVENMORE
> Then output should be: bTEXTHEREbMOREbEVENMORE
>
> I imagine this would be handled by a simple regular expression call, but
I'm
> no pro with them yet.
>
> Any help?
>
> Thanks,
> Ken
> [EMAIL PROTECTED]
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> To contact the list administrators, e-mail: [EMAIL PROTECTED]
>
>



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Reg ex help-Removing extra blank spaces before HTML output

2001-12-05 Thread Jack Dempsey

actually it does... james' solution will work but I forgot to mention a
\s is whitespace, not a space, therefore it will get tabs, newlines, and
spaces. look at http://www.cs.tut.fi/~jkorpela/perl/regexp.html
" \s matches any whitespace character (space, tab, newline)"
therefore my suggestion works: 
$t = preg_replace('/\s+/',' ',$text);
its quicker to code, easier to understand, and will run faster because
it doesn't have to match and remember or do alternation...

jack

-Original Message-
From: Ken [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, December 05, 2001 2:01 PM
To: Jack Dempsey
Subject: RE: [PHP] Reg ex help-Removing extra blank spaces before HTML
output

At 10:57 AM 12/5/01 -0500, Jack Dempsey wrote:
>a space (\s is from perl)

Ah, OK, yours doesn't deal with newlines.

 From list member "James", a solution that does:

-
From: "liljim" <[EMAIL PROTECTED]>

The example Jack gave you will clear up spaces well, though to get both
newlines and spaces into one:

$input = preg_replace("/([ ]|\n){1,}/", "\\1", $input);
-

Thanks again!

- Ken
[EMAIL PROTECTED]



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Reg Ex to search for both Integer and Comma-spaced Integer

2003-07-01 Thread Kevin Stone
I'm a little confused by something.  I need to build a reg-ex to scrape for
both plain integers and comma spaced integers in the same place in the same
string at the same time.  For example..

$string = "Mark's average score was 544.";
preg_match("/average score was ([0-9]+)/", $string, $matches);
$score = $matches(1);

$string = "Julie's average score was 10,443.";
preg_match("/average score was ([0-9]+,[0-9]+)/", $string, $matches);
$score = $matches(1);

How do I combine these two queries so that the reg-ex matches both the comma
spaced integer and regular integer?

Thanks!
- Kevin



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



Re: [PHP] Reg Ex to search for both Integer and Comma-spaced Integer

2003-07-01 Thread Jason Wong
On Wednesday 02 July 2003 01:07, Kevin Stone wrote:

You have started a new thread by taking an existing posting and replying to
it while you changed the subject.

That is bad, because it breaks threading. Whenever you reply to a message,
your mail client generates a "References:" header that tells all recipients
which posting(s) your posting refers to. A mail client uses this information
to build a threaded view ("tree view") of the postings.

With your posting style you successfully torpedoed this useful feature; your
posting shows up within an existing thread it has nothing to do with.

Always do a fresh post when you want to start a new thread. To achieve this,
click on "New message" instead of "Reply" within your mail client, and enter
the list address as the recipient. You can save the list address in your
address book for convenience.


> I'm a little confused by something.  I need to build a reg-ex to scrape for
> both plain integers and comma spaced integers in the same place in the same
> string at the same time.  For example..

[snip]

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.biz
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *
--
Search the list archives before you post
http://marc.theaimsgroup.com/?l=php-general
--
/*
I am just a nice, clean-cut Mongolian boy.
-- Yul Brynner, 1956
*/


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



RE: [PHP] Reg Ex to search for both Integer and Comma-spaced Integer

2003-07-01 Thread Ford, Mike [LSS]
> -Original Message-
> From: Kevin Stone [mailto:[EMAIL PROTECTED]
> Sent: 01 July 2003 18:07
> 
> $string = "Mark's average score was 544.";
> preg_match("/average score was ([0-9]+)/", $string, $matches);
> $score = $matches(1);
> 
> $string = "Julie's average score was 10,443.";
> preg_match("/average score was ([0-9]+,[0-9]+)/", $string, $matches);
> $score = $matches(1);
> 
> How do I combine these two queries so that the reg-ex matches 
> both the comma
> spaced integer and regular integer?

  preg_match("/average score was ([0-9]+(,[0-9]+)*)/", $string, $matches);

should do it.

Cheers!

Mike

-
Mike Ford,  Electronic Information Services Adviser,
Learning Support Services, Learning & Information Services,
JG125, James Graham Building, Leeds Metropolitan University,
Beckett Park, LEEDS,  LS6 3QS,  United Kingdom
Email: [EMAIL PROTECTED]
Tel: +44 113 283 2600 extn 4730  Fax:  +44 113 283 3211 


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



Re: [PHP] Reg Ex to search for both Integer and Comma-spaced Integer

2003-07-01 Thread Kevin Stone

- Original Message -
From: "Ford, Mike [LSS]" <[EMAIL PROTECTED]>
To: "'Kevin Stone'" <[EMAIL PROTECTED]>; "PHP-General"
<[EMAIL PROTECTED]>
Sent: Tuesday, July 01, 2003 12:19 PM
Subject: RE: [PHP] Reg Ex to search for both Integer and Comma-spaced
Integer


> > -Original Message-
> > From: Kevin Stone [mailto:[EMAIL PROTECTED]
> > Sent: 01 July 2003 18:07
> >
> > $string = "Mark's average score was 544.";
> > preg_match("/average score was ([0-9]+)/", $string, $matches);
> > $score = $matches(1);
> >
> > $string = "Julie's average score was 10,443.";
> > preg_match("/average score was ([0-9]+,[0-9]+)/", $string, $matches);
> > $score = $matches(1);
> >
> > How do I combine these two queries so that the reg-ex matches
> > both the comma
> > spaced integer and regular integer?
>
>   preg_match("/average score was ([0-9]+(,[0-9]+)*)/", $string, $matches);
>
> should do it.
>
> Cheers!
>
> Mike

Excelent thinking Mike that's exactly the result I was after.  Thanks!
- Kevin



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