[PHP] ereg_replace to preg_replace translation

2009-08-11 Thread m a r k u s

Hi all,

I see that from PHP 5.3.0 ereg_replace() function is deprecated and throws a 
warning.
I would like to use the preg_replace() function as an alternative of ereg_replace() function but... 
can't undestand the \n#[^\n]*\n expression.


$sql = ereg_replace(\n#[^\n]*\n, , $sql);

Any help for tranlation or alternative ?
Thanks

--
m a r k u s

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



Re: [PHP] ereg_replace to preg_replace translation

2009-08-11 Thread Shawn McKenzie
m a r k u s wrote:
 Hi all,
 
 I see that from PHP 5.3.0 ereg_replace() function is deprecated and
 throws a warning.
 I would like to use the preg_replace() function as an alternative of
 ereg_replace() function but... can't undestand the \n#[^\n]*\n
 expression.
 
 $sql = ereg_replace(\n#[^\n]*\n, , $sql);
 
 Any help for tranlation or alternative ?
 Thanks
 
 -- 
 m a r k u s

Here's a good regex tutorial:  http://www.regular-expressions.info/

But to answer your question, \n#[^\n]*\n means the match must:

start with a newline(\n) followed by a pound sign (#) followed by 0 or
more characters (*) that are not a newline(^\n) all the way up to
another newline (\n).

To translate to preg I think all you need to do is give it delimiters,
but that may not be necessary, not sure. |\n#[^\n]*\n|

-- 
Thanks!
-Shawn
http://www.spidean.com

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



RE: [PHP] ereg_replace to preg_replace translation

2009-08-11 Thread Ford, Mike
 -Original Message-
 From: m a r k u s [mailto:queribus2...@hotmail.com]
 Sent: 11 August 2009 15:34
 
 I see that from PHP 5.3.0 ereg_replace() function is deprecated and
 throws a warning.
 I would like to use the preg_replace() function as an alternative of
 ereg_replace() function but...
 can't undestand the \n#[^\n]*\n expression.
 
 $sql = ereg_replace(\n#[^\n]*\n, , $sql);

Generally the only change you need to make for transition from ereg to preg 
(for simple expressions, anyway) is the addition of pattern delimiters. So the 
above becomes, for example:

  $sql = preg_replace(|\n#[^\n]*\n|, , $sql);

Although I would argue that those \ characters should be escaped (and should 
have been even for ereg), so the more correct version of this is:

  $sql = preg_replace(|\\n#[^\\n]*\\n|, , $sql);


Cheers!

Mike
 -- 
Mike Ford,
Electronic Information Developer, Libraries and Learning Innovation,  
Leeds Metropolitan University, C507, Civic Quarter Campus, 
Woodhouse Lane, LEEDS,  LS1 3HE,  United Kingdom 
Email: m.f...@leedsmet.ac.uk 
Tel: +44 113 812 4730





To view the terms under which this email is distributed, please go to 
http://disclaimer.leedsmet.ac.uk/email.htm

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



Re: [PHP] ereg_replace with user defined function?

2006-10-11 Thread Frank Arensmeier


10 okt 2006 kl. 19.25 skrev Roman Neuhauser:


# [EMAIL PROTECTED] / 2006-10-09 22:01:34 +0200:

Thank you Ilaria and Roman for your input. I did not know that preg
is able to deal with PCRE patterns.


preg is obviously short for Perl REGular expressions, while
PCRE positively means Perl-Compatible Regular Expressions.
The regexp syntax from Perl is a superset of POSIX extended
regexps, so anything ereg_ function accept will be good for
preg_ as well (but beware of pattern delimiters).


Thanks for the info. I didn't know that.




As a matter of fact I came up
with the following solution (if someone is interested):


What problem does it solve? I mean, why are you trying to avoid
preg_replace_callback() in the first place?



Maybe because I didn't know better? Initially, I was using  
ereg_replace for replacing metric numbers with imperial ones. But  
obviously, ereg_replace replaces all instances in the given text  
string. A text containing more than one instance of the same unit,  
was replaced by the calculated replacement string of the first  
finding. So I had to think about other ways to do this - which  
brought me to preg_replace_callback (as I already said - I didn't  
know that preg takes POSIX patterns as well).


Would you suggest a different way? Would it be faster to do the  
replacement with preg_replace_callback compared to the function I wrote?


A page like this one: http://www.nikehydraulics.com/products/ 
product_chooser_gb.php?productMaingroup=5productSubgroup=33


.. gets converted within 0.32 / 0.34 seconds which I think is quite ok.

/frank



the function takes a text and an array with converters like:

$converters[] = array ( metric = mm, imperial = in,
ratio  = 0.039370079, round = 1 );
$converters[] = array ( metric = m, imperial = ft, ratio
= 3.280839895, round = 1 );


function convertTextString ( $text, $convertTable )
{
# this function takes a text string, searches for numbers to
convert, convert those numbers and returns
# the complete text again.

if ( !ereg ( [[:digit:]], $text ) ) // if the text does not
contain any numbers, return the text as it is
{
return $text;
}

foreach ( $convertTable as $convertKey = $convertUnit )
{
$pattern =
		((\d{1,10}[,|.]*\d{0,10})*(\s)(%s)([$|\s|.|,|\)|/]+| $)); //  
this regex
looks for a number followed by white space,  followed by the  
metric unit,

followed by a closing character like  ., , or )
$pattern = sprintf ( $pattern, $convertUnit['metric'] );

while ( preg_match ( $pattern, $text, $matches ) )
{
$matches[1] = str_replace ( ,, ., $matches[1] );
			// in case  numbers are written like 6,6 m, we need to  
replace , with

.
// because we do not want to return 0, we have to
make shure that  the new value is not zero.
$itterator = 0;
do {
$value = round ( ( $matches[1] *
$convertUnit['ratio'] ),  $convertUnit['round'] 
+ $itterator  );
++$itterator;
} while ( $value == 0 || $itterator == 10 );

$replacement = $value . $2 .
$convertUnit['imperial'] . $4;
$text = preg_replace ( $pattern, $replacement,
$text, 1 );
}
}
return $text;
}


--
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991



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



Re: [PHP] ereg_replace with user defined function?

2006-10-11 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2006-10-11 09:52:51 +0200:
 
 10 okt 2006 kl. 19.25 skrev Roman Neuhauser:
 
 # [EMAIL PROTECTED] / 2006-10-09 22:01:34 +0200:
 Thank you Ilaria and Roman for your input. I did not know that preg
 is able to deal with PCRE patterns.
 
 preg is obviously short for Perl REGular expressions, while
 PCRE positively means Perl-Compatible Regular Expressions.
 The regexp syntax from Perl is a superset of POSIX extended
 regexps, so anything ereg_ function accept will be good for
 preg_ as well (but beware of pattern delimiters).
 
 Thanks for the info. I didn't know that.

NP, glad to be of help. The relationship is quite obvious if you
look at both syntaxes.

 As a matter of fact I came up
 with the following solution (if someone is interested):
 
 What problem does it solve? I mean, why are you trying to avoid
 preg_replace_callback() in the first place?
 
 
 Maybe because I didn't know better?

Well your question mentioned preg_replace_callback() so I thought
maybe there was something about the function you didn't like.

 Initially, I was using  ereg_replace for replacing metric numbers with
 imperial ones. But  obviously, ereg_replace replaces all instances in
 the given text  string. A text containing more than one instance of
 the same unit,  was replaced by the calculated replacement string of
 the first  finding. So I had to think about other ways to do this -
 which  brought me to preg_replace_callback (as I already said - I
 didn't  know that preg takes POSIX patterns as well).
 
 Would you suggest a different way? Would it be faster to do the  
 replacement with preg_replace_callback compared to the function I wrote?

Definitely, and probably by several orders of magnitude.

 A page like this one: http://www.nikehydraulics.com/products/ 
 product_chooser_gb.php?productMaingroup=5productSubgroup=33
 
 .. gets converted within 0.32 / 0.34 seconds which I think is quite ok.

If the time covers only the conversion then it's quite terrible.

Looking at the convertTextString() function below there's a few
obvious optimizations waiting to be done, and... turning the foreach
into a single preg_replace_callback() is the one that begs
implementing the most (the code below's been tested and works):

class convertor
{
const SI_to_Imperial = 0;
const Imperial_to_SI = 1;

function convert($amount, $unit, $direction)
{
return sprintf(
whatever '%s' of '%s' is in the Imperial system
  , $amount
  , $unit
);
}
}
function callbackSI2IS(array $SIspec)
{
return convertor::convert(
$SIspec[1]
  , $SIspec[2]
  , convertor::SI_to_Imperial
);
}

$p = '~
((?:\d+[,|.])*\d+) # amount
\s*
(m{1,2}\b) # meters or millis
 ~x';
echo preg_replace_callback(
$p
  , 'callbackSI2IS'
  , file_get_contents('php://stdin')
);


 the function takes a text and an array with converters like:
 
 $converters[] = array ( metric = mm, imperial = in,
 ratio  = 0.039370079, round = 1 );
 $converters[] = array ( metric = m, imperial = ft, ratio
 = 3.280839895, round = 1 );
 
 
 function convertTextString ( $text, $convertTable )
 {
 # this function takes a text string, searches for numbers to
 convert, convert those numbers and returns
 # the complete text again.
 
 if ( !ereg ( [[:digit:]], $text ) ) // if the text does not
 contain any numbers, return the text as it is
 {
 return $text;
 }
 
 foreach ( $convertTable as $convertKey = $convertUnit )
 {
 $pattern =
 ((\d{1,10}[,|.]*\d{0,10})*(\s)(%s)([$|\s|.|,|\)|/]+| $)); 
 //  this regex
 looks for a number followed by white space,  followed by the  
 metric unit,
 followed by a closing character like  ., , or )
 $pattern = sprintf ( $pattern, $convertUnit['metric'] );
 
 while ( preg_match ( $pattern, $text, $matches ) )
 {
 $matches[1] = str_replace ( ,, ., $matches[1] );
 // in case  numbers are written like 6,6 m, we 
 need to  replace , with
 .
 // because we do not want to return 0, we have to
 make shure that  the new value is not zero.
 $itterator = 0;
 do {
 $value = round ( ( $matches[1] *
 $convertUnit['ratio'] ),  
 $convertUnit['round'] + $itterator  );
 ++$itterator;
 } while ( $value == 0 || $itterator == 10 );
 
 $replacement = $value . $2 .
 $convertUnit['imperial'] . $4;
 

Re: [PHP] ereg_replace with user defined function?

2006-10-11 Thread Frank Arensmeier

Thanks again for your suggestions.

Actually, - believe it or not - I have never written a class (I am  
still learning PHP after three years working with that language). So  
I am not quite sure of the benefits of your class. One thing I do  
realise is the benefit of replacing the foreach loop with a single  
preg_replace_callbak. Let me try to sum up:


With a preg_replace_callback I am able to look for a pattern like: a  
number ( float or integer ) followed by whitespace followed by one,  
two, three or more characters, followed by a closing character.


e.g.: ((\d{1,10}[,|.]*\d{0,10})*(\s)(\D{1,3})([$|\s|.|,|\)|/]+|  
$)) (untested)


If preg finds a match, it will pass an array to the specified  
function. In that function I evaluate the unit, see if it is in my  
array containing the conversion table. If that is the case,  
calculate the new value and return everything. Right?


I will get back with this new approach.

BTW, 0.32/0.34 seconds includes: calling the original html page from  
an outside server, loading this page into the DOM parser, walking  
through every table and every text string on that page. Convert  
everything necessary (the converter array contains about 14 metric -  
imperial converters) replace all converted DOM nodes and output  
everything. The metric / imperial calculations / replacements take  
between 0.00054 and 0.005 seconds per table cell / text string.


/frank

11 okt 2006 kl. 13.39 skrev Roman Neuhauser:


# [EMAIL PROTECTED] / 2006-10-11 09:52:51 +0200:


10 okt 2006 kl. 19.25 skrev Roman Neuhauser:


# [EMAIL PROTECTED] / 2006-10-09 22:01:34 +0200:

Thank you Ilaria and Roman for your input. I did not know that preg
is able to deal with PCRE patterns.


   preg is obviously short for Perl REGular expressions, while
   PCRE positively means Perl-Compatible Regular Expressions.
   The regexp syntax from Perl is a superset of POSIX extended
   regexps, so anything ereg_ function accept will be good for
   preg_ as well (but beware of pattern delimiters).


Thanks for the info. I didn't know that.


NP, glad to be of help. The relationship is quite obvious if you
look at both syntaxes.


As a matter of fact I came up
with the following solution (if someone is interested):


   What problem does it solve? I mean, why are you trying to avoid
   preg_replace_callback() in the first place?



Maybe because I didn't know better?


Well your question mentioned preg_replace_callback() so I thought
maybe there was something about the function you didn't like.

Initially, I was using  ereg_replace for replacing metric numbers  
with

imperial ones. But  obviously, ereg_replace replaces all instances in
the given text  string. A text containing more than one instance of
the same unit,  was replaced by the calculated replacement string of
the first  finding. So I had to think about other ways to do this -
which  brought me to preg_replace_callback (as I already said - I
didn't  know that preg takes POSIX patterns as well).

Would you suggest a different way? Would it be faster to do the
replacement with preg_replace_callback compared to the function I  
wrote?


Definitely, and probably by several orders of magnitude.


A page like this one: http://www.nikehydraulics.com/products/
product_chooser_gb.php?productMaingroup=5productSubgroup=33

.. gets converted within 0.32 / 0.34 seconds which I think is  
quite ok.


If the time covers only the conversion then it's quite terrible.

Looking at the convertTextString() function below there's a few
obvious optimizations waiting to be done, and... turning the  
foreach

into a single preg_replace_callback() is the one that begs
implementing the most (the code below's been tested and works):

class convertor
{
const SI_to_Imperial = 0;
const Imperial_to_SI = 1;

function convert($amount, $unit, $direction)
{
return sprintf(
whatever '%s' of '%s' is in the Imperial system
  , $amount
  , $unit
);
}
}
function callbackSI2IS(array $SIspec)
{
return convertor::convert(
$SIspec[1]
  , $SIspec[2]
  , convertor::SI_to_Imperial
);
}

$p = '~
((?:\d+[,|.])*\d+) # amount
\s*
(m{1,2}\b) # meters or millis
 ~x';
echo preg_replace_callback(
$p
  , 'callbackSI2IS'
  , file_get_contents('php://stdin')
);



the function takes a text and an array with converters like:

$converters[] = array ( metric = mm, imperial = in,
ratio  = 0.039370079, round = 1 );
$converters[] = array (	metric = m, imperial = ft,  
ratio

= 3.280839895, round = 1 );


function convertTextString ( $text, $convertTable )
{
# this function takes a text string, searches for numbers to
convert, convert those numbers and returns
# the complete text again.

if ( !ereg ( 

Re: [PHP] ereg_replace with user defined function?

2006-10-11 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2006-10-11 14:28:21 +0200:
 Actually, - believe it or not - I have never written a class (I am  
 still learning PHP after three years working with that language). So  
 I am not quite sure of the benefits of your class.

Nevermind then. I don't know how to fit my experience into a short
email, so I'm not going to explain it, just replace the class with
whatever pays the bill.

 Let me try to sum up:
 
 With a preg_replace_callback I am able to look for a pattern like: a  
 number ( float or integer ) followed by whitespace followed by one,  
 two, three or more characters, followed by a closing character.
 
 e.g.: ((\d{1,10}[,|.]*\d{0,10})*(\s)(\D{1,3})([$|\s|.|,|\)|/]+|$)) 
 (untested)

that's wrong unless you want e. g. these to match:

1|2|3|4 (^)
00|,. [EMAIL PROTECTED]
 
 If preg finds a match, it will pass an array to the specified  
 function. In that function I evaluate the unit, see if it is in my  
 array containing the conversion table. If that is the case,  
 calculate the new value and return everything. Right?

Yes.
 
 I will get back with this new approach.
 
 BTW, 0.32/0.34 seconds includes: calling the original html page from  
 an outside server, loading this page into the DOM parser

(...) ok then

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

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



Re: [PHP] ereg_replace with user defined function?

2006-10-10 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2006-10-09 22:01:34 +0200:
 Thank you Ilaria and Roman for your input. I did not know that preg  
 is able to deal with PCRE patterns.

preg is obviously short for Perl REGular expressions, while
PCRE positively means Perl-Compatible Regular Expressions.
The regexp syntax from Perl is a superset of POSIX extended
regexps, so anything ereg_ function accept will be good for
preg_ as well (but beware of pattern delimiters).

 As a matter of fact I came up  
 with the following solution (if someone is interested):
 
What problem does it solve? I mean, why are you trying to avoid
preg_replace_callback() in the first place?

 the function takes a text and an array with converters like:
 
 $converters[] = array (   metric = mm, imperial = in, 
 ratio  = 0.039370079, round = 1 );
 $converters[] = array (   metric = m, imperial = ft, ratio 
 = 3.280839895, round = 1 );
 
 
 function convertTextString ( $text, $convertTable )
 {
   # this function takes a text string, searches for numbers to  
 convert, convert those numbers and returns
   # the complete text again.
 
   if ( !ereg ( [[:digit:]], $text ) ) // if the text does not  
 contain any numbers, return the text as it is
   {
   return $text;
   }
   
   foreach ( $convertTable as $convertKey = $convertUnit )
   {
   $pattern = 
   ((\d{1,10}[,|.]*\d{0,10})*(\s)(%s)([$|\s|.|,|\)|/]+| $)); // 
 this regex 
 looks for a number followed by white space,  followed by the metric unit, 
 followed by a closing character like  ., , or )
   $pattern = sprintf ( $pattern, $convertUnit['metric'] );
   
   while ( preg_match ( $pattern, $text, $matches ) )
   {
   $matches[1] = str_replace ( ,, ., $matches[1] ); 
   // in case  numbers are written like 6,6 m, we need 
 to replace , with 
 .
   // because we do not want to return 0, we have to 
   make shure that  the new value is not zero.
   $itterator = 0;
   do {
   $value = round ( ( $matches[1] * 
   $convertUnit['ratio'] ),  $convertUnit['round'] 
 + $itterator  );
   ++$itterator;
   } while ( $value == 0 || $itterator == 10 );
   
   $replacement = $value . $2 . 
   $convertUnit['imperial'] . $4;
   $text = preg_replace ( $pattern, $replacement, 
   $text, 1 );
   }
   }
   return $text;
 }

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

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



[PHP] ereg_replace with unser defined function?

2006-10-09 Thread Frank Arensmeier

Hello all.

Is it possible to have a user defined function for the replacement  
within an ereg_replace (like preg_replace_callback)? I am working on  
a script that converts html pages with metric data into imperial  
data. My script takes text strings containing one or more instances  
of e.g. 123 mm, 321 mm, 123 kg, 123 cm2 and so on. The script  
searches the string with a pattern like:

([[:digit:]]+|[[:digit:]]+\.[[:digit:]]+)([[:blank:]]?)(mm)

When the script finds an instance, it stores the matches into an  
array - ereg ( $pattern, $textstring, $matches )


The replacement (for mm) looks like:
round ( ( $matches[1] * 0.039370079 ), 1 ) . $matches[2]  . in

Everything is working great accept when the string contains more than  
one instance for example of the metric unit mm. In that case, all  
instances of xy mm will be replaced with the first occurrence.


So, a text like:

The product is 230 mm tall, 120 mm thick and 340 mm wide will  
output as The product is 9.1 in tall, 9.1 in thick and 9.1 in wide  
- because the replacement string is based / calculated on the first  
occurrence 230 mm.


Alternatively, is there a way to limit ereg_replace to only replace  
one instance at a time?


Hopefully I am not too confusing...

regards,

/frank

ps. of course I have searched the manual and asked Google - no luck ds.



Re: [PHP] ereg_replace with unser defined function?

2006-10-09 Thread Roman Neuhauser
# [EMAIL PROTECTED] / 2006-10-09 09:46:01 +0200:
 Is it possible to have a user defined function for the replacement  
 within an ereg_replace (like preg_replace_callback)? I am working on  
 a script that converts html pages with metric data into imperial  
 data. My script takes text strings containing one or more instances  
 of e.g. 123 mm, 321 mm, 123 kg, 123 cm2 and so on. The script  
 searches the string with a pattern like:
 ([[:digit:]]+|[[:digit:]]+\.[[:digit:]]+)([[:blank:]]?)(mm)

your pattern is valid PCRE AFAICS. why don't you just use
preg_replace_callback? it's faster, more capable...

-- 
How many Vietnam vets does it take to screw in a light bulb?
You don't know, man.  You don't KNOW.
Cause you weren't THERE. http://bash.org/?255991

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



Re: [PHP] ereg_replace with unser defined function?

2006-10-09 Thread Ilaria De Marinis

Hi Frank,
I think preg_replace_callback is a good solution for you.

If you don't want to use it, you can construct two arrays defining 
matches and replacements.


For example:
$matches
[230]
[120]
[340]

$replacements
[9.1]
[replace2]
[replace3]



After you stored matches in $matches using regular expression like 
yours,/preg_match_all 
http://it.php.net/manual/en/function.preg-split.php/ 
(([[:digit:]]+|[[:digit:]]+\.[[:digit:]]+)([[:blank:]]?)(mm), $string, 
$matches, PREG_SET_ORDER)


you can define $replacements by this way:
for(int =0; icount($matches); i++){
   $replacements[$i]=round((substr($matches[$i][0], 0, 
3))*0.039370079),1); //take the last part of match with no digits, I 
don't know if there are sure 3 digits

}

for(int i=0; icount($matches); i++){
   preg_replace($string, $matches[$i][0], $replacement[$i].in);
}

hope to help you

Ilaria

Frank Arensmeier wrote:


Hello all.

Is it possible to have a user defined function for the replacement  
within an ereg_replace (like preg_replace_callback)? I am working on  
a script that converts html pages with metric data into imperial  
data. My script takes text strings containing one or more instances  
of e.g. 123 mm, 321 mm, 123 kg, 123 cm2 and so on. The script  
searches the string with a pattern like:

([[:digit:]]+|[[:digit:]]+\.[[:digit:]]+)([[:blank:]]?)(mm)

When the script finds an instance, it stores the matches into an  
array - ereg ( $pattern, $textstring, $matches )


The replacement (for mm) looks like:
round ( ( $matches[1] * 0.039370079 ), 1 ) . $matches[2]  . in

Everything is working great accept when the string contains more than  
one instance for example of the metric unit mm. In that case, all  
instances of xy mm will be replaced with the first occurrence.


So, a text like:

The product is 230 mm tall, 120 mm thick and 340 mm wide will  
output as The product is 9.1 in tall, 9.1 in thick and 9.1 in wide  
- because the replacement string is based / calculated on the first  
occurrence 230 mm.


Alternatively, is there a way to limit ereg_replace to only replace  
one instance at a time?


Hopefully I am not too confusing...

regards,

/frank

ps. of course I have searched the manual and asked Google - no luck ds.




--

De Marinis Ilaria
Settore Automazione Biblioteche
Phone: +3906-44486052
CASPUR - Via dei Tizii ,6b - 00185 Roma
e-mail: [EMAIL PROTECTED]


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



Re: [PHP] ereg_replace with user defined function?

2006-10-09 Thread Frank Arensmeier
Thank you Ilaria and Roman for your input. I did not know that preg  
is able to deal with PCRE patterns. As a matter of fact I came up  
with the following solution (if someone is interested):


the function takes a text and an array with converters like:

$converters[] = array (	metric = mm, imperial = in, ratio  
= 0.039370079, round = 1 );
$converters[] = array (	metric = m, imperial = ft, ratio  
= 3.280839895, round = 1 );



function convertTextString ( $text, $convertTable )
{
	# this function takes a text string, searches for numbers to  
convert, convert those numbers and returns

# the complete text again.

	if ( !ereg ( [[:digit:]], $text ) ) // if the text does not  
contain any numbers, return the text as it is

{
return $text;
}

foreach ( $convertTable as $convertKey = $convertUnit )
{
		$pattern = ((\d{1,10}[,|.]*\d{0,10})*(\s)(%s)([$|\s|.|,|\)|/]+| 
$)); // this regex looks for a number followed by white space,  
followed by the metric unit, followed by a closing character like  
., , or )

$pattern = sprintf ( $pattern, $convertUnit['metric'] );

while ( preg_match ( $pattern, $text, $matches ) )
{
			$matches[1] = str_replace ( ,, ., $matches[1] ); // in case  
numbers are written like 6,6 m, we need to replace , with .
			// because we do not want to return 0, we have to make shure that  
the new value is not zero.

$itterator = 0;
do {
$value = round ( ( $matches[1] * $convertUnit['ratio'] ),  
$convertUnit['round'] + $itterator  );

++$itterator;
} while ( $value == 0 || $itterator == 10 );

$replacement = $value . $2 . $convertUnit['imperial'] . 
$4;
$text = preg_replace ( $pattern, $replacement, $text, 1 
);
}
}
return $text;
}

/frank

9 okt 2006 kl. 16.18 skrev Ilaria De Marinis:


Hi Frank,
I think preg_replace_callback is a good solution for you.

If you don't want to use it, you can construct two arrays defining  
matches and replacements.


For example:
$matches
[230]
[120]
[340]

$replacements
[9.1]
[replace2]
[replace3]



After you stored matches in $matches using regular expression like  
yours,/preg_match_all http://it.php.net/manual/en/function.preg- 
split.php/ (([[:digit:]]+|[[:digit:]]+\.[[:digit:]]+)([[:blank:]]?) 
(mm), $string, $matches, PREG_SET_ORDER)


you can define $replacements by this way:
for(int =0; icount($matches); i++){
   $replacements[$i]=round((substr($matches[$i][0], 0, 3)) 
*0.039370079),1); //take the last part of match with no digits, I  
don't know if there are sure 3 digits

}

for(int i=0; icount($matches); i++){
   preg_replace($string, $matches[$i][0], $replacement[$i].in);
}

hope to help you

Ilaria

Frank Arensmeier wrote:


Hello all.

Is it possible to have a user defined function for the  
replacement  within an ereg_replace (like preg_replace_callback)?  
I am working on  a script that converts html pages with metric  
data into imperial  data. My script takes text strings containing  
one or more instances  of e.g. 123 mm, 321 mm, 123 kg, 123  
cm2 and so on. The script  searches the string with a pattern like:

([[:digit:]]+|[[:digit:]]+\.[[:digit:]]+)([[:blank:]]?)(mm)

When the script finds an instance, it stores the matches into an   
array - ereg ( $pattern, $textstring, $matches )


The replacement (for mm) looks like:
round ( ( $matches[1] * 0.039370079 ), 1 ) . $matches[2]  . in

Everything is working great accept when the string contains more  
than  one instance for example of the metric unit mm. In that  
case, all  instances of xy mm will be replaced with the first  
occurrence.


So, a text like:

The product is 230 mm tall, 120 mm thick and 340 mm wide will   
output as The product is 9.1 in tall, 9.1 in thick and 9.1 in  
wide  - because the replacement string is based / calculated on  
the first  occurrence 230 mm.


Alternatively, is there a way to limit ereg_replace to only  
replace  one instance at a time?


Hopefully I am not too confusing...

regards,

/frank

ps. of course I have searched the manual and asked Google - no  
luck ds.





--

De Marinis Ilaria
Settore Automazione Biblioteche
Phone: +3906-44486052
CASPUR - Via dei Tizii ,6b - 00185 Roma
e-mail: [EMAIL PROTECTED]


--
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] ereg_replace help

2004-03-18 Thread Richard Davey
Hi all,

I'm sure this is blindingly simple, but could anyone tell me how to
get an ereg_replace() to return a string where all characters OTHER
than alpha-numerics have been stripped out?

I can do the reverse with:

$output = ereg_replace('[[:alnum:]]', '', $string);

Which will happily remove all alpha-numeric characters from $string!
But I want it to remove anything but.. suggestions please?

-- 
Best regards,
 Richard Davey
 http://www.phpcommunity.org/wiki/296.html

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



Re: [PHP] ereg_replace help

2004-03-18 Thread John W. Holmes
From: Richard Davey [EMAIL PROTECTED]

 I'm sure this is blindingly simple, but could anyone tell me how to
 get an ereg_replace() to return a string where all characters OTHER
 than alpha-numerics have been stripped out?

$output = ereg_replace('[^a-zA-Z0-9]','',$string);

The ^ is NOT (when the first character in a bracketed character set). So
anything NOT alphanumeric is replaced.

---John Holmes...

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



Re: [PHP] ereg_replace help

2004-03-18 Thread Chris Hayes
At 16:21 18-3-04, you wrote:

I can do the reverse with:

$output = ereg_replace('[[:alnum:]]', '', $string);

Which will happily remove all alpha-numeric characters from $string!
But I want it to remove anything but.. suggestions please?


did you try
$output = ereg_replace('[^[:alnum:]]', '', $string);
?
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re[2]: [PHP] ereg_replace help

2004-03-18 Thread Richard Davey
Hello Chris,

Thursday, March 18, 2004, 3:28:01 PM, you wrote:

CH did you try
CH $output = ereg_replace('[^[:alnum:]]', '', $string);
CH ?

Nope, because in the only reference book I had to hand it said the ^
matched the start of a string so it didn't occur to me to try it.

Thanks to John I now know when used in a block it's no longer limited
to the start of the string. The code you posted above works, thanks.

-- 
Best regards,
 Richard Davey
 http://www.phpcommunity.org/wiki/296.html

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



Re: Re[2]: [PHP] ereg_replace help

2004-03-18 Thread trlists
On 18 Mar 2004 Richard Davey wrote:

 Nope, because in the only reference book I had to hand it said the ^
 matched the start of a string so it didn't occur to me to try it.
 
 Thanks to John I now know when used in a block it's no longer limited
 to the start of the string. The code you posted above works, thanks.

The '^' has a totally different meaning inside a character class than 
its meaning outside the class.  It's not a amtter of it being limited 
so much as just different (actually I guess overloaded is the real 
term).

--
Tom

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



[PHP] ereg_replace

2004-02-10 Thread Nicole Lallande
Can anyone tell me why this does not work:

$str1=ereg_replace(index.php?src=,index/,$url);

is there another way to do this?

Thanks,

Nicole

--

Nicole Lallande
[EMAIL PROTECTED]
760.753.6766

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


Re: [PHP] ereg_replace

2004-02-10 Thread Jason Wong
On Wednesday 11 February 2004 01:55, Nicole Lallande wrote:
 Can anyone tell me why this does not work:

 $str1=ereg_replace(index.php?src=,index/,$url);

Because '.' and '?' have special meanings in a regex.

 is there another way to do this?

If it's a plain simple string replace you want then use str_replace().

-- 
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
--
/*
The Gordian Maxim:
If a string has one end, it has another.
*/

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



Re: [PHP] ereg_replace

2004-02-10 Thread Richard Davey
Hello Nicole,

Tuesday, February 10, 2004, 5:55:01 PM, you wrote:

NL Can anyone tell me why this does not work:
NL $str1=ereg_replace(index.php?src=,index/,$url);

Because it's an invalid regular expression.

NL is there another way to do this?

Yes, str_replace() for something this simple:

$str1 = str_replace(index.php?src=, index/, $url);

-- 
Best regards,
 Richardmailto:[EMAIL PROTECTED]

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



Re: [PHP] ereg_replace -- Thanks!

2004-02-10 Thread Nicole Lallande
Many thanks!!

Richard Davey wrote:

Hello Nicole,

Tuesday, February 10, 2004, 5:55:01 PM, you wrote:

NL Can anyone tell me why this does not work:
NL $str1=ereg_replace(index.php?src=,index/,$url);
Because it's an invalid regular expression.

NL is there another way to do this?

Yes, str_replace() for something this simple:

$str1 = str_replace(index.php?src=, index/, $url);

 

--

Nicole Lallande
[EMAIL PROTECTED]
760.753.6766

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


Re: [PHP] ereg_replace help

2003-11-18 Thread Eugene Lee
On Tue, Nov 18, 2003 at 04:37:52PM +1100, Martin Towell wrote:
: 
: I have an array of strings in the following format:
:   abcd - rst
:   abcd - uvw
:   abcd - xyz
:   foobar - rst
:   blah - rst
:   googol - uvw
: 
: What I want to do is strip everything from the  -  bit of the string to
: the end, _but_ only for the strings that don't start with abcd
: 
: I was thinking something like the following:
:   echo ereg_replace((!abcd) - xyz, \\1, $str).\n;
: but obviously this doesn't work, otherwise I wouldn't be emailing the
: list...

You can't use ! because it's not a valid special character in regular
expressions.  It's really hard to craft do-not-match-this-word patterns.
You're better off separating the two pieces of logic.

$arr = array(
abcd - rst,
abcd - uvw,
abcd - xyz,
foobar - rst,
blah - rst,
googol - uvw
);

reset($arr);
while (list($key, $value) = each($arr))
{
if (substr($value, 0, 5) != 'abcd ')
{
$arr[$key] = ereg_replace('^(.*) - .*$', '\1', $value);
}
}

print_r($arr);

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



Re: [PHP] ereg_replace help

2003-11-18 Thread Jason Wong
On Tuesday 18 November 2003 13:37, Martin Towell wrote:

 I have an array of strings in the following format:
   abcd - rst
   abcd - uvw
   abcd - xyz
   foobar - rst
   blah - rst
   googol - uvw

 What I want to do is strip everything from the  -  bit of the string to
 the end, _but_ only for the strings that don't start with abcd

 I was thinking something like the following:
   echo ereg_replace((!abcd) - xyz, \\1, $str).\n;
 but obviously this doesn't work, otherwise I wouldn't be emailing the
 list...

 Can anyone help? I need to use ereg_replace() because it's part of our code
 library and therefore can't change :(

May be quicker (definitely easier) to explode() on ' - '.

-- 
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
--
/*
The giraffe you thought you offended last week is willing to be nuzzled today.
*/

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



Re: [PHP] ereg_replace help

2003-11-18 Thread Henrik Hudson
On Monday 17 November 2003 23:37,
Martin Towell [EMAIL PROTECTED] sent a missive stating:

 Hi All,

 I have an array of strings in the following format:
   abcd - rst
   abcd - uvw
   abcd - xyz
   foobar - rst
   blah - rst
   googol - uvw

 What I want to do is strip everything from the  -  bit of the string to
 the end, _but_ only for the strings that don't start with abcd

 I was thinking something like the following:
   echo ereg_replace((!abcd) - xyz, \\1, $str).\n;
 but obviously this doesn't work, otherwise I wouldn't be emailing the
 list...

 Can anyone help? I need to use ereg_replace() because it's part of our code
 library and therefore can't change :(

 TIA
 Martin

Possibly have to do a if statement, ereg for the abcd and then if ture, do 
your ereg replace? I can't logically think how that would work in one regex, 
since you want to match first and then replace...but my regex skills aren't 
top notch either :)

Henrik
-- 
Henrik Hudson
[EMAIL PROTECTED]

`If there's anything more important than my ego
around, I want it caught and shot now.' 
--Hitchhikers Guide to the Galaxy

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



Re: [PHP] ereg_replace help

2003-11-18 Thread Robert Cummings
On Tue, 2003-11-18 at 02:30, Jason Wong wrote:
 On Tuesday 18 November 2003 13:37, Martin Towell wrote:
 
  I have an array of strings in the following format:
  abcd - rst
  abcd - uvw
  abcd - xyz
  foobar - rst
  blah - rst
  googol - uvw
 
  What I want to do is strip everything from the  -  bit of the string to
  the end, _but_ only for the strings that don't start with abcd
 
  I was thinking something like the following:
  echo ereg_replace((!abcd) - xyz, \\1, $str).\n;
  but obviously this doesn't work, otherwise I wouldn't be emailing the
  list...
 
  Can anyone help? I need to use ereg_replace() because it's part of our code
  library and therefore can't change :(
 
 May be quicker (definitely easier) to explode() on ' - '.

The following is untested:

---

foreach( $myArray as $id = $entry )
{
if( ($pos = strpos( 'abcd' ) !== false  $pos === 0 )
{
$parts = explode( ' - ', $entry );
$myArray[$id] = $parts[0];
}
}

print_r( $myArray );

---

Cheers,
Rob.
-- 
..
| InterJinn Application Framework - http://www.interjinn.com |
::
| An application and templating framework for PHP. Boasting  |
| a powerful, scalable system for accessing system services  |
| such as forms, properties, sessions, and caches. InterJinn |
| also provides an extremely flexible architecture for   |
| creating re-usable components quickly and easily.  |
`'

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



Re: [PHP] ereg_replace help

2003-11-18 Thread Curt Zirzow
* Thus wrote Martin Towell ([EMAIL PROTECTED]):
 Hi All,
 
 I have an array of strings in the following format:
   abcd - rst
   abcd - uvw
   abcd - xyz
   foobar - rst
   blah - rst
   googol - uvw
 
 What I want to do is strip everything from the  -  bit of the string to
 the end, _but_ only for the strings that don't start with abcd
 
 I was thinking something like the following:
   echo ereg_replace((!abcd) - xyz, \\1, $str).\n;
 but obviously this doesn't work, otherwise I wouldn't be emailing the
 list...
 

$newarray = preg_replace('/((?!abcd) - (.*))$/', '\\3', $array);

 Can anyone help? I need to use ereg_replace() because it's part of our code
 library and therefore can't change :(

How do you mean its part of your code library? I would strongly
suggest using preg_* for its speed and capabilites.

Curt
-- 
My PHP key is worn out

  PHP List stats since 1997: 
http://zirzow.dyndns.org/html/mlists/

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



RE: [PHP] ereg_replace help

2003-11-18 Thread Martin Towell
 * Thus wrote Martin Towell ([EMAIL PROTECTED]):
  Hi All,
  
  I have an array of strings in the following format:
  abcd - rst
  abcd - uvw
  abcd - xyz
  foobar - rst
  blah - rst
  googol - uvw
  
  What I want to do is strip everything from the  -  bit of 
 the string to
  the end, _but_ only for the strings that don't start with abcd
  
  I was thinking something like the following:
  echo ereg_replace((!abcd) - xyz, \\1, $str).\n;
  but obviously this doesn't work, otherwise I wouldn't be 
 emailing the
  list...
  
 
 $newarray = preg_replace('/((?!abcd) - (.*))$/', '\\3', $array);
 
  Can anyone help? I need to use ereg_replace() because it's 
 part of our code
  library and therefore can't change :(
 
 How do you mean its part of your code library? I would strongly
 suggest using preg_* for its speed and capabilites.
 
 Curt


thanks for everyone's help... 

 How do you mean its part of your code library?

I mean that the function I'm having to call is passed an array (coming from
a databse) and it has an option to do an ereg_replace() on the incoming
array. Due to the amount of other code relying on it, is very hard to change
without causing something strange to happen elsewhere :(

If all the code was mine, then I wouldn't have any reservations on changing
it in an instant. I'm having to improve the code gradually (good luck to me)

Martin

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



[PHP] ereg_replace help

2003-11-17 Thread Martin Towell
Hi All,

I have an array of strings in the following format:
abcd - rst
abcd - uvw
abcd - xyz
foobar - rst
blah - rst
googol - uvw

What I want to do is strip everything from the  -  bit of the string to
the end, _but_ only for the strings that don't start with abcd

I was thinking something like the following:
echo ereg_replace((!abcd) - xyz, \\1, $str).\n;
but obviously this doesn't work, otherwise I wouldn't be emailing the
list...

Can anyone help? I need to use ereg_replace() because it's part of our code
library and therefore can't change :(

TIA
Martin

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



[PHP] ereg_replace()

2003-11-15 Thread erythros
ok, so i'm stupid. how do i replace all '? ' with '?? '

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



Re: [PHP] ereg_replace()

2003-11-15 Thread Chris Shiflett
--- erythros [EMAIL PROTECTED] wrote:
 ok, so i'm stupid. how do i replace all '? ' with '?? '

$foo = '? ';
$bar = str_replace('? ', '?? ', $foo);

Hope that helps.

Chris

=
Chris Shiflett - http://shiflett.org/

PHP Security Handbook
 Coming mid-2004
HTTP Developer's Handbook
 http://httphandbook.org/
RAMP Training Courses
 http://www.nyphp.org/ramp

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



Re: [PHP] ereg_replace()

2003-11-15 Thread Justin French
On Sunday, November 16, 2003, at 02:31  PM, erythros wrote:

ok, so i'm stupid. how do i replace all '? ' with '?? '

No need for regular expressions here.

?
$str = 'well, how do I do this? should i experiment?';
$newStr = str_replace('? ','?? ',$str);
echo $newStr;
// should echo well, how do I do this?? should i experiment?
?
Unless you want ANY white space (\n, \t, etc) instead of just spaces, 
an ereg would be better.  I prefer preg_replace():

?
$str = 'well, how do I do this? should i experiment?';
$newStr = str_replace('/?(\s)/','??\\1',$str);
echo $newStr;
?
Justin French

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


Re: [PHP] ereg_replace()

2003-11-15 Thread erythros
chris and justin, you guys rock. thanx for pointing towards str_replace().
my code works now. thanx!

Justin French [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
 On Sunday, November 16, 2003, at 02:31  PM, erythros wrote:

  ok, so i'm stupid. how do i replace all '? ' with '?? '
 

 No need for regular expressions here.

 ?
 $str = 'well, how do I do this? should i experiment?';
 $newStr = str_replace('? ','?? ',$str);
 echo $newStr;
 // should echo well, how do I do this?? should i experiment?
 ?

 Unless you want ANY white space (\n, \t, etc) instead of just spaces,
 an ereg would be better.  I prefer preg_replace():

 ?
 $str = 'well, how do I do this? should i experiment?';
 $newStr = str_replace('/?(\s)/','??\\1',$str);
 echo $newStr;
 ?


 Justin French

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



RE: [PHP] ereg_replace vs. preg_replace [was: str_replace question]

2003-09-10 Thread Wouter van Vliet
thanks, that pretty much cleared things up.. 

 - -Oorspronkelijk bericht-
 - Van: Curt Zirzow [mailto:[EMAIL PROTECTED]
 - Verzonden: woensdag 10 september 2003 6:30
 - Aan: [EMAIL PROTECTED]
 - Onderwerp: Re: [PHP] ereg_replace vs. preg_replace [was: str_replace
 - question]
 - 
 - 
 - * Thus wrote Wouter van Vliet ([EMAIL PROTECTED]):
 -  
 -  Btw, does anybody know why preg_replace is adviced over 
 - ereg_replace in the
 -  manual? .. and if ereg_replace doesn't have any advantages over
 -  preg_replace, couldn't this function get depricated?
 - 
 - I've done some testing with  ereg and preg functions and
 - preg beats ereg by quite a bite (sorry don't have results)
 - 
 - preg is much more advanced and can do a lot more things than ereg
 - can. I think just by looking at the documentation (two separate
 - pages, not related to the functions), you can see that it is rather
 - thorough.
 - 
 - The biggest disadvantage  with preg is that since it is complex,
 - mistakes can easily be overlooked.
 - 
 - Only since 4.2.0 has preg_* functions been compiled by default so
 - if a person wanted to write scripts that were portable across many
 - different hosting sites  they would use ereg_* functions.
 - 
 - As for being deprecated, I doubt that will happen (as
 - mentioned above) ereg_* has been around for many years, since early
 - 3.x versions.  Php developers may be familiar with the posix syntax
 - so instead of learning the perl version they have the option to use
 - the ereg_* functions.
 - 
 - Although I haven't heard any (php) claims as such but some 
 - people may want
 - to be 100% POSIX compatible :)
 -  
 - 
 - Curt
 - -- 
 - I used to think I was indecisive, but now I'm not so sure.
 - 
 - -- 
 - 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] ereg_replace vs. preg_replace [was: str_replace question]

2003-09-09 Thread Curt Zirzow
* Thus wrote Wouter van Vliet ([EMAIL PROTECTED]):
 
 Btw, does anybody know why preg_replace is adviced over ereg_replace in the
 manual? .. and if ereg_replace doesn't have any advantages over
 preg_replace, couldn't this function get depricated?

I've done some testing with  ereg and preg functions and
preg beats ereg by quite a bite (sorry don't have results)

preg is much more advanced and can do a lot more things than ereg
can. I think just by looking at the documentation (two separate
pages, not related to the functions), you can see that it is rather
thorough.

The biggest disadvantage  with preg is that since it is complex,
mistakes can easily be overlooked.

Only since 4.2.0 has preg_* functions been compiled by default so
if a person wanted to write scripts that were portable across many
different hosting sites  they would use ereg_* functions.

As for being deprecated, I doubt that will happen (as
mentioned above) ereg_* has been around for many years, since early
3.x versions.  Php developers may be familiar with the posix syntax
so instead of learning the perl version they have the option to use
the ereg_* functions.

Although I haven't heard any (php) claims as such but some people may want
to be 100% POSIX compatible :)
 

Curt
-- 
I used to think I was indecisive, but now I'm not so sure.

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



[PHP] ereg_replace

2003-07-01 Thread alexander sundli
I'm trying to replace singel line comment with empty string.

tried ereg_replace(//.+\n,'',$string); but this replaces all text after
//.

anyone now what to do?



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



Re: [PHP] ereg_replace

2003-07-01 Thread Dean E. Weimer

 I'm trying to replace singel line comment with empty string.

 tried ereg_replace(//.+\n,'',$string); but this replaces all text after
 //.

 anyone now what to do?

 \n is the newline character, making the string apear to be multiple lines
see the thread [PHP] multi line regular expression? and see if that
helps you any.




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




-- 
Thanks,
  Dean E. Weimer
  http://www.dwiemer.org/
  [EMAIL PROTECTED]

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



RE: [PHP] ereg_replace and quotation marks

2003-06-25 Thread Boaz Yahav
Your example should work
Maybe something else is the problem?

Sincerely

berber

Visit http://www.weberdev.com/ Today!!!
To see where PHP might take you tomorrow.


-Original Message-
From: Paul Nowosielski [mailto:[EMAIL PROTECTED] 
Sent: Tuesday, June 24, 2003 8:45 PM
To: [EMAIL PROTECTED]
Subject: [PHP] ereg_replace and quotation marks


I'm trying to strip quotation marks out of user from input but it
doesn't seem to work correctly.

$string=ereg_replace(\,,$string);

I get a \ mark after I run a quote  through the form. When I want the
quote turned to nothing.

Any suggestions??

Paul
 


-- 
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] ereg_replace and quotation marks

2003-06-25 Thread Paul Nowosielski
I think it has to do with magic quotes
Oh well no worries :)


On Wed, 2003-06-25 at 03:59, Boaz Yahav wrote:
 Your example should work
 Maybe something else is the problem?
 
 Sincerely
 
 berber
 
 Visit http://www.weberdev.com/ Today!!!
 To see where PHP might take you tomorrow.
 
 
 -Original Message-
 From: Paul Nowosielski [mailto:[EMAIL PROTECTED] 
 Sent: Tuesday, June 24, 2003 8:45 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] ereg_replace and quotation marks
 
 
 I'm trying to strip quotation marks out of user from input but it
 doesn't seem to work correctly.
 
 $string=ereg_replace(\,,$string);
 
 I get a \ mark after I run a quote  through the form. When I want the
 quote turned to nothing.
 
 Any suggestions??
 
 Paul
  
-- 
What good are computers? They can only give you answers. ~ Pablo
Picasso


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



[PHP] ereg_replace and quotation marks

2003-06-24 Thread Paul Nowosielski
I'm trying to strip quotation marks out of user from input but it
doesn't seem to work correctly.

$string=ereg_replace(\,,$string);

I get a \ mark after I run a quote  through the form. When I want the
quote turned to nothing.

Any suggestions??

Paul
 


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



[PHP] ereg_replace question

2003-06-11 Thread Todd Cary




I have a string,

D:\Htdocs\gilardi\barcode\php\testwrite.php

from

 $fullpath = $HTTP_SERVER_VARS[PATH_TRANSLATED];

I want to remove the "testwrite.php" leaving

D:\Htdocs\gilardi\barcode\php\

This does not work

 $fullpath = $HTTP_SERVER_VARS[PATH_TRANSLATED];
 $fullpath = ereg_replace("\\[^\\]+$","",$fullpath) . '\\';

What have I missed?

Todd

-- 

 




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 pre../pre
b) doesnt contain any pre
c) doesnt contain any /pre
d) contains multiple pre../pre'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(.*?)\/pre(.*)/is';
$re2 = '/br\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 pre/pre pairs...
// you need to add a line break instead of the br
// to keep your code formatted
$result .= 'pre'.preg_replace($re2, \n, $arMatch[2]).'/pre';
$string = $arMatch[3];
}
else break;
}

// if there are no pre/pre 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 pre, PRE, 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




[PHP] ereg_replace();

2002-11-12 Thread Gustaf Sjoberg
Hi,
i'm trying to replace every instance of br within the pre../pre 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 pre and /pre.

example $string:

testbr
testbr
testbr
pre
testingbr
testingbr
/pre
testbr
testbr

i want that to look like:

testbr
testbr
testbr
pre
testing
testing
/pre
testbr
testbr

-- 
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 Ernest E Vogelsinger
At 17:49 12.11.2002, Gustaf Sjoberg spoke out and said:
[snip]
Hi,
i'm trying to replace every instance of br within the pre../pre 
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 pre and /pre.
[snip] 

You need a two-phase operation on this:

1) isolate all pre/pre elements
   preg_match('/(.*?)pre(.*?)\/pre(.*)/is', $string, $armatch);

$armatch now contains:
   [0] all, ignore this
   [1] everything before pre
   [2] everything within pre/pre
   [3] the rest after /pre

2) go on and replace all br's here:
   preg_replace('/br\n?/is', \n, $armatch[2]);

The whole stuff would look something like

/* UNTESTED */
function kill_br_within_pre($string)
{
$re1 = '/(.*?)pre(.*?)\/pre(.*)/is';
$re2 = '/br\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 pre are properly closed with /pre. 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/



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 br within the pre../pre 
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 pre and /pre.
[snip] 

You need a two-phase operation on this:

1) isolate all pre/pre elements
   preg_match('/(.*?)pre(.*?)\/pre(.*)/is', $string, $armatch);

$armatch now contains:
   [0] all, ignore this
   [1] everything before pre
   [2] everything within pre/pre
   [3] the rest after /pre

2) go on and replace all br's here:
   preg_replace('/br\n?/is', \n, $armatch[2]);

The whole stuff would look something like

/* UNTESTED */
function kill_br_within_pre($string)
{
$re1 = '/(.*?)pre(.*?)\/pre(.*)/is';
$re2 = '/br\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 pre are properly closed with /pre. 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




Re: [PHP] ereg_replace();

2002-11-12 Thread Ernest E Vogelsinger
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/



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 pre../pre
b) doesnt contain any pre
c) doesnt contain any /pre
d) contains multiple pre../pre's

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

?
function remove_br_in_pre($string)
{
unset($result);
if (!preg_match('/(.*?pre)(.*?)(\/pre)(.*)/is', $string))
{
if (!preg_match('/pre/is', $string))
return $string;
else
$string .= /pre;
}
while ($string)
{
preg_match('/(.*?pre)(.*?)(\/pre)(.*)/is', $string, $arMatch); 
  
if (is_array($arMatch))
{
$result .= $arMatch[1];
$result .= str_replace('br','',$arMatch[2]);
$result .= $arMatch[3];
if (!preg_match('/pre/is', $arMatch[4]))
{
$result .= $arMatch[4];
return $result;
}
$string = $arMatch[4];
}
else break;
}
}
//test string
$param = 
testbrtestbrprebrtestingbrtestingbr/pretestbrtestbrtestpretestbrtest/pretestingbrtest;
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 Ernest E Vogelsinger
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 pre../pre
b) doesnt contain any pre
c) doesnt contain any /pre
d) contains multiple pre../pre'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(.*?)\/pre(.*)/is';
$re2 = '/br\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 pre/pre pairs...
// you need to add a line break instead of the br
// to keep your code formatted
$result .= 'pre'.preg_replace($re2, \n, $arMatch[2]).'/pre';
$string = $arMatch[3];
}
else break;
}

// if there are no pre/pre 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 pre, PRE, 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/



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




[PHP] ereg_replace???

2002-10-28 Thread Shawn McKenzie
I need to replace all NON alpha-numeric characters in a string.

Example:
   input:  -What's Up Doc?
   output: WhatsUpDoc

I received this in a previous post, but it doesn't work:
   $str = ereg_replace(/[^[:alnum:]]/i, '', $str);

Thanks!
Shawn



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




RE: [PHP] ereg_replace???

2002-10-28 Thread John W. Holmes
 I need to replace all NON alpha-numeric characters in a string.
 
 Example:
input:  -What's Up Doc?
output: WhatsUpDoc
 
 I received this in a previous post, but it doesn't work:
$str = ereg_replace(/[^[:alnum:]]/i, '', $str);

Use preg_replace() with that string, not ereg_replace().

---John Holmes...



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




Re: [PHP] ereg_replace???

2002-10-28 Thread Shawn McKenzie
Thanks!

Why does preg_replace(^\W^,,$str); not remove undescores _ ?  Are they
alpha-numeric?

I had to do this preg_replace(^\W|_^,,$str);

TIA,
Shawn

John W. Holmes [EMAIL PROTECTED] wrote in message
news:000201c27eab$f4ea0500$7c02a8c0;coconut...
  I need to replace all NON alpha-numeric characters in a string.
 
  Example:
 input:  -What's Up Doc?
 output: WhatsUpDoc
 
  I received this in a previous post, but it doesn't work:
 $str = ereg_replace(/[^[:alnum:]]/i, '', $str);

 Use preg_replace() with that string, not ereg_replace().

 ---John Holmes...





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




[PHP] ereg_replace()

2002-08-14 Thread Liam MacKenzie

Hi guys,

I'm looking to get a specific bit of data out of a slightly complex amount
of data.
Ok, I have this in a variable:

User : [EMAIL PROTECTED]
Dir : /home/eXtremail/mbox/i-redlands.net/3/1/liam
Forward :
Copy :
Account mapping :
User Disk Quota : 0
Disk Space Used : 0
Max In Mail Size : 0
Max Out Mail Size : 0
Autoreply : No
Mailbox Access : POP,IMAP
Created : Sat Jul 6 09:21:23 2002
Status : Enabled


This is different for every user as you can see.  For instance, the Dir is
different for everyone, such is the Created date.
I need to extract the User Disk Quota and the Disk Space Used variables out
of this.  How would I go about doing that?

Is there an easier function to use than ereg_replace?

Thanks in advance!
Liam




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




[PHP] ereg_replace problems

2002-05-22 Thread Zac Hillier

I'm trying to replace values within a string with a value looked up from a database. I 
have a function that looks up the value in the database for me but I'm having trouble 
passing the value to the function because of  the backslashes, is there a way around 
this?

Code:

$cntnt = eregi_replace(\[L=([a-zA-Z]+)].([a-zA-Z]+)\[EL], a href=\ . 
fndLnk(\\1) . \\\2/a, $cntnt);

fndLnk is the function and the error I receive is -

Warning: Unexpected character in input: '\' (ASCII=92) state=1 

Thanks for any help

Zac


Re: [PHP] ereg_replace problems

2002-05-22 Thread Analysis Solutions

Zac:

 $cntnt = eregi_replace(\[L=([a-zA-Z]+)].([a-zA-Z]+)\[EL], 
 a href=\ . fndLnk(\\1) . \\\2/a, $cntnt);

Put \\1 in double quotes so it gets evaluated as a substring.

  a href=\ . fndLnk(\\1) . \\\2/a, $cntnt);

Enjoy,

--Dan

-- 
   PHP classes that make web design easier
SQL Solution  |   Layout Solution   |  Form Solution
sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

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




[PHP] ereg_replace or chr bug?

2002-03-28 Thread Ando

Ok, what i wanna do is replace the codes in html with ascii equivalents:

$text= ereg_replace('#([0-9]+);' , chr('\1') , $text);
But somehow it doesnt work, i have no idea why.

When i use
$text= ereg_replace('#([0-9]+);' , '\1' , $text);
it replaces everything correctly

But
$text= ereg_replace('#([0-9]+);' , chr('\1') , $text);
just replaces everything with an empty string

using php 3.0.12




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




RE: [PHP] ereg_replace or chr bug?

2002-03-28 Thread Rick Emery

From the manual for chr()

Returns a one-character string containing the character specified by ascii.

It replaces one (1) character, not a string

-Original Message-
From: Ando [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 28, 2002 6:59 AM
To: [EMAIL PROTECTED]
Subject: [PHP] ereg_replace or chr bug?


Ok, what i wanna do is replace the codes in html with ascii equivalents:

$text= ereg_replace('#([0-9]+);' , chr('\1') , $text);
But somehow it doesnt work, i have no idea why.

When i use
$text= ereg_replace('#([0-9]+);' , '\1' , $text);
it replaces everything correctly

But
$text= ereg_replace('#([0-9]+);' , chr('\1') , $text);
just replaces everything with an empty string

using php 3.0.12




-- 
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] ereg_replace or chr bug?

2002-03-28 Thread Ando

Not sure what you mean here
$text= ereg_replace('#([0-9]+);' , chr('\1') , $text);

should replace for example #65; with chr('65') (\1 means everything in
brackets in regular expression), which is 'A'   .

Rick Emery wrote:

 From the manual for chr()

 Returns a one-character string containing the character specified by ascii.

 It replaces one (1) character, not a string


 -Original Message-
 From: Ando [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, March 28, 2002 6:59 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP] ereg_replace or chr bug?

 Ok, what i wanna do is replace the codes in html with ascii equivalents:

 $text= ereg_replace('#([0-9]+);' , chr('\1') , $text);
 But somehow it doesnt work, i have no idea why.

 When i use
 $text= ereg_replace('#([0-9]+);' , '\1' , $text);
 it replaces everything correctly

 But
 $text= ereg_replace('#([0-9]+);' , chr('\1') , $text);
 just replaces everything with an empty string

 using php 3.0.12

 --
 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] ereg_replace or chr bug?

2002-03-28 Thread Rick Emery

chr() expects you to pass it a numeric value.  You are passing it a string.
For instance,
if $text= #45, then you are trying to do:  chr(45), which is not the
same as chr(45).
Hence, ereg_replace() fails and simply returns the original string, $text.

-Original Message-
From: Ando [mailto:[EMAIL PROTECTED]]
Sent: Thursday, March 28, 2002 7:08 AM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] ereg_replace or chr bug?


Not sure what you mean here
$text= ereg_replace('#([0-9]+);' , chr('\1') , $text);

should replace for example #65; with chr('65') (\1 means everything in
brackets in regular expression), which is 'A'   .

Rick Emery wrote:

 From the manual for chr()

 Returns a one-character string containing the character specified by
ascii.

 It replaces one (1) character, not a string


 -Original Message-
 From: Ando [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, March 28, 2002 6:59 AM
 To: [EMAIL PROTECTED]
 Subject: [PHP] ereg_replace or chr bug?

 Ok, what i wanna do is replace the codes in html with ascii equivalents:

 $text= ereg_replace('#([0-9]+);' , chr('\1') , $text);
 But somehow it doesnt work, i have no idea why.

 When i use
 $text= ereg_replace('#([0-9]+);' , '\1' , $text);
 it replaces everything correctly

 But
 $text= ereg_replace('#([0-9]+);' , chr('\1') , $text);
 just replaces everything with an empty string

 using php 3.0.12

 --
 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] ereg_replace or chr bug?

2002-03-28 Thread Ando

Uh why do you think that?
Try
print chr(65);
works the same as as
print chr(65);

Rick Emery wrote:

 chr() expects you to pass it a numeric value.  You are passing it a string.
 For instance,
 if $text= #45, then you are trying to do:  chr(45), which is not the
 same as chr(45).
 Hence, ereg_replace() fails and simply returns the original string, $text.

 -Original Message-
 From: Ando [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, March 28, 2002 7:08 AM
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP] ereg_replace or chr bug?

 Not sure what you mean here
 $text= ereg_replace('#([0-9]+);' , chr('\1') , $text);

 should replace for example #65; with chr('65') (\1 means everything in
 brackets in regular expression), which is 'A'   .

 Rick Emery wrote:

  From the manual for chr()
 
  Returns a one-character string containing the character specified by
 ascii.
 
  It replaces one (1) character, not a string

 
  -Original Message-
  From: Ando [mailto:[EMAIL PROTECTED]]
  Sent: Thursday, March 28, 2002 6:59 AM
  To: [EMAIL PROTECTED]
  Subject: [PHP] ereg_replace or chr bug?
 
  Ok, what i wanna do is replace the codes in html with ascii equivalents:
 
  $text= ereg_replace('#([0-9]+);' , chr('\1') , $text);
  But somehow it doesnt work, i have no idea why.
 
  When i use
  $text= ereg_replace('#([0-9]+);' , '\1' , $text);
  it replaces everything correctly
 
  But
  $text= ereg_replace('#([0-9]+);' , chr('\1') , $text);
  just replaces everything with an empty string
 
  using php 3.0.12
 
  --
  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] ereg_replace Help

2002-03-21 Thread lists

Hi all,

I have a large file that I am trying to parse.

I have a many lines that look like this


\\text1

I need an expression that will change \\text1 to text1=

so if I have something like this

\\text1 

asdfkjaslkfj
asdlfkjasljkf
asdlkfjasldfkj
asldkfjalskfj

\\text2 
erweiurwoeir
werqwer
qwer
qwerqw
er

\\text3

asdlfkw
xcvsdf
zxcvcgn
sdfgwr
xcdfvszdfg


it will become

text1 = 

asdfkjaslkfj
asdlfkjasljkf
asdlkfjasldfkj
asldkfjalskfj
 text2 = erweiurwoeir
werqwer
qwer
qwerqw
er
 text3 = asdlfkw
xcvsdf
zxcvcgn
sdfgwr
xcdfvszdfg



Any Ideas,
Michael



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




[PHP] ereg_replace

2002-02-18 Thread Mitch Tishaw

I need a little help with the ereg_replace function.  I have the following code:

$text = ereg_replace([[:alpha:]]+://[^[:space:]]+[[:alnum:]/],a href=\\\0
\\\0/a, $text);

which pads a url with an href tag to make it clickable.  Here's what I would 
like to do:  In the case of the url ending with .gif or .jpg, I would like to 
pad it with an img src tag instead, so it shows up as an actual picture.  Does 
anyone know how I can modify the above code to do this?  Thanks in advance.

Mitch

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




Re: [PHP] ereg_replace

2002-02-18 Thread Erik Price


On Monday, February 18, 2002, at 03:44  PM, Mitch Tishaw wrote:

 I need a little help with the ereg_replace function.  I have the 
 following code:

 $text = ereg_replace([[:alpha:]]+://[^[:space:]]+[[:alnum:]/],a 
 href=\\\0
 \\\0/a, $text);

 which pads a url with an href tag to make it clickable.  Here's what I 
 would
 like to do:  In the case of the url ending with .gif or .jpg, I would 
 like to
 pad it with an img src tag instead, so it shows up as an actual 
 picture.  Does
 anyone know how I can modify the above code to do this?  Thanks in 
 advance.

This will not necessarily work every single time, nor will it ONLY work 
on images, but I tried -- maybe it can help you.  So why don't you test 
it out on maybe ten or so different image URLs.  If it works, go with 
it, but I accept no liability.  (Also, this regex has not been optimized 
for speed -- sorry, I don't have time to play with it.)

$text = http://www.domain.com/directory/images/image.jpg;
preg_replace((http://[^\s]+[-a-zA-Z0-9_/.]+\.(gif|jpg|jpeg)$), img 
src=\\1\ /, $text);

HTH


Erik





Erik Price
Web Developer Temp
Media Lab, H.H. Brown
[EMAIL PROTECTED]


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




RE: [PHP] ereg_replace help

2002-02-04 Thread Lars Torben Wilson

On Sun, 2002-02-03 at 21:34, Martin Towell wrote:
 is that a direct copy from your code? - if it is, there's two errors
 1. you have a comma just before the closing backet
 2. the function is : implode(string glue, array pieces)
so that would be : $content = implode(\n, $lines);
ie. the two arguments are the wrong way around
 Martin

Actually, implode() will take its arguments in either order, so
there's really only one thing (the comma) which could be causing
the problem.

Also, for the original poster: if you only need to do simple 
string replacements, you should see whether str_replace() will
serve your purpose. It's much less expensive than ereg_replace().
If you feel that you require regular expressions, the preg_*()
functions are less expensive than the ereg_*() equivalents.


Torben

 -Original Message-
 From: John P. Donaldson [mailto:[EMAIL PROTECTED]]
 Sent: Monday, February 04, 2002 4:32 PM
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP] ereg_replace help
 
 
 I'm not actually replacing \n with br, I just used
 that as an example.  When I tried Martin's solution, I
 got a parse error on this line:
 
 $content = implode($lines, \n,); 
 
 I checked the manual and it's constructed properly ..
 I think.  What could be giving me the parse error on
 this line.  The previous line reads:
 
 $lines = file(log.txt);
 
 Thanks,
 John
 
 
 
 
 --- Mike Frazer [EMAIL PROTECTED] wrote:
  nl2br() would serve that purpose as well.  See the
  Strings section of the
  Functions Reference in the manual.
  
  Mike Frazer
  
  
  
  Martin Towell [EMAIL PROTECTED] wrote in
  message
 
 [EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
   $lines = file(filename_here.blah);  // read in
  file as an array
   $content = implode(\n, $lines); // join it
  all back together
   $new_cont = ereg_replace(from, to, $content);
   fopen(...);  fputs(..., $new_content); 
  fclose(...);
  
  
   if your intent is to replace all new lines with
  br's then use this
  instead
   ...
  
   $lines = file(filename_here.blah);  // read in
  file as an array
   $content = implode(br, $lines);   // join it
  all back together
   fopen(...);  fputs(..., $content);  fclose(...);
  
  
   hope this helps
  
   -Original Message-
   From: John P. Donaldson
  [mailto:[EMAIL PROTECTED]]
   Sent: Monday, February 04, 2002 3:39 PM
   To: php
   Subject: [PHP] ereg_replace help
  
  
   I have a file open and can successfully write to
  it,
   but I was to be able to search for a certain
  string of
   text and replace it with a string of text.  I
  can't
   figure out how to construct a proper ereg_replace
   statement to search through this file and do the
   replacing.  Examples I've seen are in the manner
  of:
  
   $text = line1\nline2\n;
   fputs(ereg_replace(\n, br, $text));
  
   But how do I set the value of $text to be the
  entire
   contents of the text file I've got open so it can
   search through the entire file to find matches and
   replace those matches?  Any help is greatly
   appreciated.
  
   Thanks,
   John
  
   __
   Do You Yahoo!?
   Great stuff seeking new owners in Yahoo! Auctions!
   http://auctions.yahoo.com
  
   --
   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
  
 
 
 __
 Do You Yahoo!?
 Great stuff seeking new owners in Yahoo! Auctions! 
 http://auctions.yahoo.com
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
-- 
 Torben Wilson [EMAIL PROTECTED]
 http://www.thebuttlesschaps.com
 http://www.hybrid17.com
 http://www.inflatableeye.com
 +1.604.709.0506


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




[PHP] ereg_replace help

2002-02-03 Thread John P. Donaldson

I have a file open and can successfully write to it,
but I was to be able to search for a certain string of
text and replace it with a string of text.  I can't
figure out how to construct a proper ereg_replace
statement to search through this file and do the
replacing.  Examples I've seen are in the manner of:

$text = line1\nline2\n;
fputs(ereg_replace(\n, br, $text));

But how do I set the value of $text to be the entire
contents of the text file I've got open so it can
search through the entire file to find matches and
replace those matches?  Any help is greatly
appreciated.

Thanks,
John

__
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions! 
http://auctions.yahoo.com

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




RE: [PHP] ereg_replace help

2002-02-03 Thread Martin Towell

$lines = file(filename_here.blah);  // read in file as an array
$content = implode(\n, $lines); // join it all back together
$new_cont = ereg_replace(from, to, $content);
fopen(...);  fputs(..., $new_content);  fclose(...);


if your intent is to replace all new lines with br's then use this instead
...

$lines = file(filename_here.blah);  // read in file as an array
$content = implode(br, $lines);   // join it all back together
fopen(...);  fputs(..., $content);  fclose(...);


hope this helps

-Original Message-
From: John P. Donaldson [mailto:[EMAIL PROTECTED]]
Sent: Monday, February 04, 2002 3:39 PM
To: php
Subject: [PHP] ereg_replace help


I have a file open and can successfully write to it,
but I was to be able to search for a certain string of
text and replace it with a string of text.  I can't
figure out how to construct a proper ereg_replace
statement to search through this file and do the
replacing.  Examples I've seen are in the manner of:

$text = line1\nline2\n;
fputs(ereg_replace(\n, br, $text));

But how do I set the value of $text to be the entire
contents of the text file I've got open so it can
search through the entire file to find matches and
replace those matches?  Any help is greatly
appreciated.

Thanks,
John

__
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions! 
http://auctions.yahoo.com

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



Re: [PHP] ereg_replace help

2002-02-03 Thread Mike Frazer

nl2br() would serve that purpose as well.  See the Strings section of the
Functions Reference in the manual.

Mike Frazer



Martin Towell [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 $lines = file(filename_here.blah);  // read in file as an array
 $content = implode(\n, $lines); // join it all back together
 $new_cont = ereg_replace(from, to, $content);
 fopen(...);  fputs(..., $new_content);  fclose(...);


 if your intent is to replace all new lines with br's then use this
instead
 ...

 $lines = file(filename_here.blah);  // read in file as an array
 $content = implode(br, $lines);   // join it all back together
 fopen(...);  fputs(..., $content);  fclose(...);


 hope this helps

 -Original Message-
 From: John P. Donaldson [mailto:[EMAIL PROTECTED]]
 Sent: Monday, February 04, 2002 3:39 PM
 To: php
 Subject: [PHP] ereg_replace help


 I have a file open and can successfully write to it,
 but I was to be able to search for a certain string of
 text and replace it with a string of text.  I can't
 figure out how to construct a proper ereg_replace
 statement to search through this file and do the
 replacing.  Examples I've seen are in the manner of:

 $text = line1\nline2\n;
 fputs(ereg_replace(\n, br, $text));

 But how do I set the value of $text to be the entire
 contents of the text file I've got open so it can
 search through the entire file to find matches and
 replace those matches?  Any help is greatly
 appreciated.

 Thanks,
 John

 __
 Do You Yahoo!?
 Great stuff seeking new owners in Yahoo! Auctions!
 http://auctions.yahoo.com

 --
 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] ereg_replace help

2002-02-03 Thread John P. Donaldson

I'm not actually replacing \n with br, I just used
that as an example.  When I tried Martin's solution, I
got a parse error on this line:

$content = implode($lines, \n,); 

I checked the manual and it's constructed properly ..
I think.  What could be giving me the parse error on
this line.  The previous line reads:

$lines = file(log.txt);

Thanks,
John




--- Mike Frazer [EMAIL PROTECTED] wrote:
 nl2br() would serve that purpose as well.  See the
 Strings section of the
 Functions Reference in the manual.
 
 Mike Frazer
 
 
 
 Martin Towell [EMAIL PROTECTED] wrote in
 message

[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
  $lines = file(filename_here.blah);  // read in
 file as an array
  $content = implode(\n, $lines); // join it
 all back together
  $new_cont = ereg_replace(from, to, $content);
  fopen(...);  fputs(..., $new_content); 
 fclose(...);
 
 
  if your intent is to replace all new lines with
 br's then use this
 instead
  ...
 
  $lines = file(filename_here.blah);  // read in
 file as an array
  $content = implode(br, $lines);   // join it
 all back together
  fopen(...);  fputs(..., $content);  fclose(...);
 
 
  hope this helps
 
  -Original Message-
  From: John P. Donaldson
 [mailto:[EMAIL PROTECTED]]
  Sent: Monday, February 04, 2002 3:39 PM
  To: php
  Subject: [PHP] ereg_replace help
 
 
  I have a file open and can successfully write to
 it,
  but I was to be able to search for a certain
 string of
  text and replace it with a string of text.  I
 can't
  figure out how to construct a proper ereg_replace
  statement to search through this file and do the
  replacing.  Examples I've seen are in the manner
 of:
 
  $text = line1\nline2\n;
  fputs(ereg_replace(\n, br, $text));
 
  But how do I set the value of $text to be the
 entire
  contents of the text file I've got open so it can
  search through the entire file to find matches and
  replace those matches?  Any help is greatly
  appreciated.
 
  Thanks,
  John
 
  __
  Do You Yahoo!?
  Great stuff seeking new owners in Yahoo! Auctions!
  http://auctions.yahoo.com
 
  --
  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
 


__
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions! 
http://auctions.yahoo.com

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




RE: [PHP] ereg_replace help

2002-02-03 Thread Martin Towell

is that a direct copy from your code? - if it is, there's two errors
1. you have a comma just before the closing backet
2. the function is : implode(string glue, array pieces)
   so that would be : $content = implode(\n, $lines);
   ie. the two arguments are the wrong way around
Martin

-Original Message-
From: John P. Donaldson [mailto:[EMAIL PROTECTED]]
Sent: Monday, February 04, 2002 4:32 PM
To: [EMAIL PROTECTED]
Subject: Re: [PHP] ereg_replace help


I'm not actually replacing \n with br, I just used
that as an example.  When I tried Martin's solution, I
got a parse error on this line:

$content = implode($lines, \n,); 

I checked the manual and it's constructed properly ..
I think.  What could be giving me the parse error on
this line.  The previous line reads:

$lines = file(log.txt);

Thanks,
John




--- Mike Frazer [EMAIL PROTECTED] wrote:
 nl2br() would serve that purpose as well.  See the
 Strings section of the
 Functions Reference in the manual.
 
 Mike Frazer
 
 
 
 Martin Towell [EMAIL PROTECTED] wrote in
 message

[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
  $lines = file(filename_here.blah);  // read in
 file as an array
  $content = implode(\n, $lines); // join it
 all back together
  $new_cont = ereg_replace(from, to, $content);
  fopen(...);  fputs(..., $new_content); 
 fclose(...);
 
 
  if your intent is to replace all new lines with
 br's then use this
 instead
  ...
 
  $lines = file(filename_here.blah);  // read in
 file as an array
  $content = implode(br, $lines);   // join it
 all back together
  fopen(...);  fputs(..., $content);  fclose(...);
 
 
  hope this helps
 
  -Original Message-
  From: John P. Donaldson
 [mailto:[EMAIL PROTECTED]]
  Sent: Monday, February 04, 2002 3:39 PM
  To: php
  Subject: [PHP] ereg_replace help
 
 
  I have a file open and can successfully write to
 it,
  but I was to be able to search for a certain
 string of
  text and replace it with a string of text.  I
 can't
  figure out how to construct a proper ereg_replace
  statement to search through this file and do the
  replacing.  Examples I've seen are in the manner
 of:
 
  $text = line1\nline2\n;
  fputs(ereg_replace(\n, br, $text));
 
  But how do I set the value of $text to be the
 entire
  contents of the text file I've got open so it can
  search through the entire file to find matches and
  replace those matches?  Any help is greatly
  appreciated.
 
  Thanks,
  John
 
  __
  Do You Yahoo!?
  Great stuff seeking new owners in Yahoo! Auctions!
  http://auctions.yahoo.com
 
  --
  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
 


__
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions! 
http://auctions.yahoo.com

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



Re: [PHP] ereg_replace help

2002-02-03 Thread Jason Wong

On Monday 04 February 2002 13:31, John P. Donaldson wrote:
 I'm not actually replacing \n with br, I just used
 that as an example.  When I tried Martin's solution, I
 got a parse error on this line:

 $content = implode($lines, \n,);

You've got a trailing comma.


-- 
Jason Wong - Gremlins Associates - www.gremlins.com.hk

/*
A halted retreat
Is nerve-wracking and dangerous.
To retain people as men -- and maidservants
Brings good fortune.
*/

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




[PHP] EREG_REPLACE?

2001-11-15 Thread Oosten, Sjoerd van


 Hello, ive got a problem
 
 I want to replace this string:
 a class=mn href=whatever is here should be left her and is
 variablethis must also be variable/a
 
 by:
 
 font size=2a class=mn href=whatever is here should be left her and
 is variablethis must also be variable/a/font
 
 So the two tags should be placed before and after the link when a link is
 in my $pagecontent
 
 I know it's easier to use another class, but for the moment that's not an
 option.
 
 Greetings,
 
 Sjoerd 
 
 
 Sjoerd van Oosten 
 Digitaal vormgever [EMAIL PROTECTED]
 Datamex E-sites B.V. 
 http://www.esites.nl
 Minervum 7368 Telefoon: (076) 5 730 730 
 4817 ZH BREDA Telefax: (076) 5 877 757 
 ___
 

-- 
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] EREG_REPLACE?

2001-11-15 Thread Mark

On Thu, 15 Nov 2001 20:09:08 +0100, Oosten, Sjoerd van wrote:

 Hello, ive got a problem

 I want to replace this string:
 a class=mn href=whatever is here should be left her and is
 variablethis must also be variable/a

 by:

 font size=2a class=mn href=whatever is here should be left
her and
 is variablethis must also be variable/a/font

try:
ereg_replace((a class=\mn\ href=\.*\.*/a),
font size=2\\1/font,$string);

 So the two tags should be placed before and after the link when a
link is
 in my $pagecontent

 I know it's easier to use another class, but for the moment that's
not an
 option.

 Greetings,

 Sjoerd

 
 Sjoerd van Oosten
 Digitaal vormgever [EMAIL PROTECTED]
 Datamex E-sites B.V.
 http://www.esites.nl
 Minervum 7368 Telefoon: (076) 5 730 730
 4817 ZH BREDA Telefax: (076) 5 877 757
 ___




--
Mark, [EMAIL PROTECTED] on 11/15/2001



--
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] ereg_replace - How do I stop it being greedy?

2001-09-07 Thread George Whiffen

Hi,

I've got a problem with regular expression syntax with ereg_replace:

ereg_replace(':start:(.*):end:','this is \\1',':start: first :end: middle :start: last 
 :end:');

   returns - this is first :end: middle :start: last

   but I want - this is first middle this is last

The problem seems to be that ereg_replace is being greedy on the match and matching as 
much as it
can 
instead of just finding the first match, handling that and then going on to the next 
match.

I can get it to work with preg_replace i.e. 

preg_replace(':start:(.*?):end:','this \\1',':start first :end: middle :start: last 
:end:')

   returns - this is first middle this is last 

But my actual string is on multiple lines, and preg_replace doesn't seem to continue 
trying
to match on the next line, whereas ereg_replace happily treats newlines just like any 
other
character.

So how do I stop ereg_replace being greedy or alternatively get preg_replace to treat 
multiple 
lines as a single source string?


George

-- 
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] ereg_replace - How do I stop it being greedy?

2001-09-07 Thread Jack Dempsey

look into the s modifier...it makes a dot match a newline as well, where
normally it wouldn't

jack

-Original Message-
From: George Whiffen [mailto:[EMAIL PROTECTED]]
Sent: Friday, September 07, 2001 1:09 PM
To: [EMAIL PROTECTED]
Subject: [PHP] ereg_replace - How do I stop it being greedy?


Hi,

I've got a problem with regular expression syntax with ereg_replace:

ereg_replace(':start:(.*):end:','this is \\1',':start: first :end: middle
:start: last  :end:');

   returns - this is first :end: middle :start: last

   but I want - this is first middle this is last

The problem seems to be that ereg_replace is being greedy on the match and
matching as much as it
can
instead of just finding the first match, handling that and then going on to
the next match.

I can get it to work with preg_replace i.e.

preg_replace(':start:(.*?):end:','this \\1',':start first :end: middle
:start: last :end:')

   returns - this is first middle this is last

But my actual string is on multiple lines, and preg_replace doesn't seem to
continue trying
to match on the next line, whereas ereg_replace happily treats newlines just
like any other
character.

So how do I stop ereg_replace being greedy or alternatively get preg_replace
to treat multiple
lines as a single source string?


George

--
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] ereg_replace - How do I stop it being greedy?

2001-09-07 Thread George Whiffen

Thanks Jack,

preg_replace with an s modifier works a treat.

I'm still curious as to how to get ereg_replace to work as well.  Everything
I read about regex/Posix Regular Expressions, seems to suggest that a ?
should also work with ereg_replace!

George



Jack Dempsey wrote:
 
 look into the s modifier...it makes a dot match a newline as well, where
 normally it wouldn't
 
 jack
 
 -Original Message-
 From: George Whiffen [mailto:[EMAIL PROTECTED]]
 Sent: Friday, September 07, 2001 1:09 PM
 To: [EMAIL PROTECTED]
 Subject: [PHP] ereg_replace - How do I stop it being greedy?
 
 Hi,
 
 I've got a problem with regular expression syntax with ereg_replace:
 
 ereg_replace(':start:(.*):end:','this is \\1',':start: first :end: middle
 :start: last  :end:');
 
returns - this is first :end: middle :start: last
 
but I want - this is first middle this is last
 
 The problem seems to be that ereg_replace is being greedy on the match and
 matching as much as it
 can
 instead of just finding the first match, handling that and then going on to
 the next match.
 
 I can get it to work with preg_replace i.e.
 
 preg_replace(':start:(.*?):end:','this \\1',':start first :end: middle
 :start: last :end:')
 
returns - this is first middle this is last
 
 But my actual string is on multiple lines, and preg_replace doesn't seem to
 continue trying
 to match on the next line, whereas ereg_replace happily treats newlines just
 like any other
 character.
 
 So how do I stop ereg_replace being greedy or alternatively get preg_replace
 to treat multiple
 lines as a single source string?
 
 George
 
 --
 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] ereg_replace

2001-07-25 Thread Clayton Dukes



Can someone tell me why this doesn't work?

$home_street = ereg_replace (  , + , $home_street);

The input is 123 happy trail
I need the output to be 123+happy+trail

Thanks,
Clayton




Re: [PHP] ereg_replace

2001-07-25 Thread Matt Greer

on 7/25/01 10:38 AM, Clayton Dukes at [EMAIL PROTECTED] wrote:

 
 
 Can someone tell me why this doesn't work?
 
 $home_street = ereg_replace (  , + , $home_street);
 
 The input is 123 happy trail
 I need the output to be 123+happy+trail

Not exactly what you wanted, but you could do

implode(+, explode( , $home_street));

Matt


-- 
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] ereg_replace

2001-07-25 Thread Jason Stechschulte

On Wed, Jul 25, 2001 at 11:38:41AM -0400, Clayton Dukes wrote:
 Can someone tell me why this doesn't work?

Not really.  You should tell us why it isn't working, and we can help
you to get it working.  What is happening?  What is all of the relevant
code?

 $home_street = ereg_replace (  , + , $home_street);
 
 The input is 123 happy trail
 I need the output to be 123+happy+trail

-- 
Jason Stechschulte
[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] ereg_replace

2001-07-25 Thread Rasmus Lerdorf

Use the urlencode() function.

Or at the very least use str_replace.

And by the way, the ereg_replace() you have works fine.  You must be doing
something silly.

-Rasmus

On Wed, 25 Jul 2001, Clayton Dukes wrote:



 Can someone tell me why this doesn't work?

 $home_street = ereg_replace (  , + , $home_street);

 The input is 123 happy trail
 I need the output to be 123+happy+trail

 Thanks,
 Clayton




-- 
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] ereg_replace

2001-07-04 Thread Marc Logemann

Hi,

short question:

i want to use ereg_replace to replace something with an array-element,
this is my code and its not working:

ereg_replace(\\$([0-9]), \$parmarray[\\1], $string);

parmarray is of course an array with some elements,
Here are the facts:

$parmarray = array (, value1, value2);
$string = foo $1 bar $2;



output: foo $parmarray[1] bar $parmarray[2]

i want of course:

output: foo value1 bar value2

any ideas? thx in advance





---
Marc Logemann
Morelogs GmbH  Co. KG
Chief Software Architect
---

-- 
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] ereg_replace

2001-04-24 Thread Wade

I am attempting to do an   ereg_replace(),  but the charachter I want to
replace is a \. Any Ideas how I make the following work?

$F_name = ereg_replace (\, , $acc_fname);
echo $F_name;

Thanks,
Wade



-- 
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] ereg_replace

2001-04-24 Thread J. Jones

On Tue, Apr 24, 2001 at 06:21:20PM -0400, Wade wrote:
 I am attempting to do an   ereg_replace(),  but the charachter I want to
 replace is a \. Any Ideas how I make the following work?
 
 $F_name = ereg_replace (\, , $acc_fname);
 echo $F_name;
 
 Thanks,
 Wade
 

use \\ 

-- 
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] ereg_replace: Replacing only first occurrence

2001-04-23 Thread Erica Douglass

I want to only replace the first occurrence of a string in a file using
ereg_replace. Should I use a loop to do this? Any suggestions? Please email
me at [EMAIL PROTECTED] with suggestions.

Thanks,
Erica



-- 
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] ereg_replace: Replacing only first occurrence

2001-04-23 Thread ~~~i LeoNid ~~

On 23 Apr 2001 13:04:36 -0700 impersonator of
[EMAIL PROTECTED] (Erica Douglass) planted I saw in
php.general:

I want to only replace the first occurrence of a string in a file using
ereg_replace. Should I use a loop to do this? Any suggestions? Please email
me at [EMAIL PROTECTED] with suggestions.

Thanks,
Erica

I think, begining from some php 4, preg_replace allows to do this,
Otherwise, you could use preg_match to find first match then strpos() to
find it position, and, finaly substr() with concatenation to your
replacement. This loong way was the first, that came to my mind for cases,
where regexp realy needed. (If they are not needed, str_replace() would
work faster/simlier, you know o'cos:). 

Note: for some strings I experience hangup, especially  w/ereg_replace,
but also, for long ones, w/preg0. Regards. Leonid.

-- 
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] ereg_replace: Help!

2001-04-23 Thread Erica Douglass

I have one ereg_replace problem that I cannot seem to fix.

I need to delete an IMG tag. The only thing I know about this tag is that 
it will contain

SRC=images/headers

in the string. Here is an example:

IMG ALT=Tools BORDER=0 HEIGHT=55 SRC=images/headers/tools.gif WIDTH=455 

I tried this, but it didn't work:

$contents = ereg_replace (IMG.*images/headers.*, , $contents);

Can someone please help?

Thanks,
Erica


-- 
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] ereg_replace: Help!

2001-04-23 Thread Plutarck

This works:

$str = 'IMG ALT=Tools BORDER=0 HEIGHT=55 SRC=images/headers/tools.gif
WIDTH=455';

echo eregi_replace(IMG.+SRC=\images/headers.*, Replaced, $str);



--
Plutarck
Should be working on something...
...but forgot what it was.


Erica Douglass [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 I have one ereg_replace problem that I cannot seem to fix.

 I need to delete an IMG tag. The only thing I know about this tag is that
 it will contain

 SRC=images/headers

 in the string. Here is an example:

 IMG ALT=Tools BORDER=0 HEIGHT=55 SRC=images/headers/tools.gif
WIDTH=455 

 I tried this, but it didn't work:

 $contents = ereg_replace (IMG.*images/headers.*, , $contents);

 Can someone please help?

 Thanks,
 Erica


 --
 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] ereg_replace

2001-02-15 Thread John Vanderbeck

 why does this

 ?php
 $string = "this is my string.";

 print $string . "br\n";

 $string = preg_replace(
 array( '/is/', '/string/'),
 array( 'is not', 'bit of text' ),
 $string
   );

 print $string . "br\n";
 ?


This happens because you are replacing  "is" with "is not" so parse your
string by hand:

"this is my string"..ok the first occurence of "is", is in the word "this",
so do the replace..the replaced part in CAPS:
"thIS NOT" .. then the second "is":
thIS NOT IS NOT" etc..I think you can see why now..

- John Vanderbeck
- Admin, GameDesign



-- 
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] ereg_replace

2001-02-15 Thread Brian V Bonini

Ah right, strings not words, I feel like a dummy now... ;-)

 -Original Message-
 From: John Vanderbeck [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, February 15, 2001 10:57 AM
 To: [EMAIL PROTECTED]; Robin Vickery; [EMAIL PROTECTED]
 Subject: Re: [PHP] ereg_replace
 
 
  why does this
 
  ?php
  $string = "this is my string.";
 
  print $string . "br\n";
 
  $string = preg_replace(
  array( '/is/', '/string/'),
  array( 'is not', 'bit of text' ),
  $string
);
 
  print $string . "br\n";
  ?
 
 
 This happens because you are replacing  "is" with "is not" so parse your
 string by hand:
 
 "this is my string"..ok the first occurence of "is", is in the 
 word "this",
 so do the replace..the replaced part in CAPS:
 "thIS NOT" .. then the second "is":
 thIS NOT IS NOT" etc..I think you can see why now..
 
 - John Vanderbeck
 - Admin, GameDesign
 
 
 
 -- 
 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] ereg_replace

2001-02-15 Thread Robin Vickery

 "VB" == "Brian V Bonini" [EMAIL PROTECTED] writes:

  Ah right, strings not words, I feel like a dummy now... ;-)

  -Original Message- From: John Vanderbeck
  [mailto:[EMAIL PROTECTED]] Sent: Thursday, February 15, 2001
  10:57 AM To: [EMAIL PROTECTED]; Robin Vickery;
  [EMAIL PROTECTED] Subject: Re: [PHP] ereg_replace
  

   $string = preg_replace(
   array( '/is/', '/string/'),
   array( 'is not', 'bit of text' ),
   $string
 );

You could specify word boundaries on each side of your string
to get the behaviour you were expecting.

 $string = preg_replace(
 array( '/\bis\b/', '/\bstring\b/'),
 array( 'is not', 'bit of text' ),
 $string
   );

-- 
Robin Vickery.
BlueCarrots, 14th Floor, 20 Eastbourne Terrace, London, W2 6LE

-- 
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] ereg_replace

2001-02-15 Thread Robin Vickery

 "VB" == "Brian V Bonini" [EMAIL PROTECTED] writes:

  Ok, but I thought the start and end chars were ^ $ i.e., ^is$ or is
  this not what you mean by bounderies?


No, not really. \b matches the start or end of a word. You can see it
clearly if you do this:

   print preg_replace( '/\b/', '-', 'this is a string' ) . "br\n"; 


It will output:

   -this- -is- -a- -string-

As it replaces all the word boundaries with a hyphen.

So the regular expression /\bis\b/ will match only the word 'is'
and not 'this' or 'isotope' or 'biscuit'.

-robin

-- 
Robin Vickery.
BlueCarrots, 14th Floor, 20 Eastbourne Terrace, London, W2 6LE

-- 
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] ereg_replace

2001-02-14 Thread Robin Vickery

 ""VB" == "Brian V Bonini" [EMAIL PROTECTED] writes:

  I know you can replace A or B or C with D but can you replace A
  with B and C with D exclusively with one call to ereg_replace or
  does this need to be done seperately?

With ereg_replace it must be done seperately, but if you use
preg_replace you can pass it a list of replacements. like this:

?php
$string = "this is my string.";

print $string . "br\n";

$string = preg_replace( 
array( '/my/', '/string/'), 
array( 'your', 'bit of text' ), 
$string 
  );

print $string . "br\n";
?

The output would be:

   this is my string.
   this is your bit of text.


-- 
Robin Vickery.
BlueCarrots, 14th Floor, 20 Eastbourne Terrace, London, W2 6LE

-- 
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] ereg_replace

2001-02-14 Thread Brian V Bonini

That's exactly what I want to do Thanks!

 -Original Message-
 From: Robin Vickery [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, February 14, 2001 5:05 AM
 To: [EMAIL PROTECTED]
 Subject: Re: [PHP] ereg_replace
 
 
  ""VB" == "Brian V Bonini" [EMAIL PROTECTED] writes:
 
   I know you can replace A or B or C with D but can you replace A
   with B and C with D exclusively with one call to ereg_replace or
   does this need to be done seperately?
 
 With ereg_replace it must be done seperately, but if you use
 preg_replace you can pass it a list of replacements. like this:
 
 ?php
 $string = "this is my string.";
 
 print $string . "br\n";
 
 $string = preg_replace( 
 array( '/my/', '/string/'), 
 array( 'your', 'bit of text' ), 
 $string 
   );
 
 print $string . "br\n";
 ?
 
 The output would be:
 
this is my string.
this is your bit of text.
 
 
 -- 
 Robin Vickery.
 BlueCarrots, 14th Floor, 20 Eastbourne Terrace, London, W2 6LE
 
 -- 
 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] ereg_replace

2001-02-13 Thread Maxim Maletsky

it replaces 'This' with 'That', some you tell to ereg what he should think
'This' is and what to replace it with.

It does only one replacement at a time.

Cheers,
Maxim Maletsky


-Original Message-
From: Brian V Bonini [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, February 14, 2001 5:31 AM
To: PHP Lists
Subject: [PHP] ereg_replace


I know you can replace A or B or C with D
but can you replace A with B and C with D
exclusively with one call to ereg_replace
or does this need to be done seperately?

-Brian



-- 
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] ereg_replace with assoc array?

2001-02-08 Thread Jaxon

Hi

Can I do this

$string = file.tpl;

while (list($pattern, $replacement) = each($array)) {
ereg_replace ($pattern, $replacement, $string);
}

echo $string;



note some assumptions below:

$array contains an assoc array:

first  foo
second bar
third  rab
fourth oof

file.tpl is this:

some html {first} 
more html {second}
even more html {third}
lots more html {fourth} 

This seems like a slow way to do this...
any advice is welcome!

tia!
jaxon


-- 
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] ereg_replace all items in a array

2001-01-29 Thread Joseph H Blythe

G'day PHP'ers

I am trying highlight the results from a search, so far I have this working but only 
if the string is an exact match ie: case sensitive, for example:

?php
$keywords = "foo";
$data = "This is a lower foo. This is an upper FOO. This is a ucase Foo";

$lower = strtolower($keywords);
$upper = strtoupper($keywords);
$ucase = ucwords($keywords);
$words = array($lower, $upper, $ucase);

while ( list($key, $val) = each($words) ) {
$hilite = "font color=\"#ff\"" . $val . "/font";
$replaced = ereg_replace($val, $hilite, $data);
}

echo $replaced;
?

Now as metioned this seems to work only for "foo" does anyone have any idea why? 

Also I need to be able to support mutiple keywords ie: foo Foo FOO, so basically I 
know I could split(" ", $keywords) then some how traverse the array making a new array 
of all possible case combinations then in my while loop replace each occurance found 
in $data with the highlighted replacment, sounds easy hmm

If anyone has any ideas or can see what I am doing wrong so far, it would be mutch 
appreciated.

Regards,

Joseph

-- 
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] ereg_replace all items in a array

2001-01-29 Thread Jeff Warrington

In article [EMAIL PROTECTED], "Joseph H
Blythe" [EMAIL PROTECTED] wrote:

What is happening is that you are replacing the variable $replaced
on each iteration of the while loop. As a result, $replaced is only
storing the most recent match.

To see this, try this out:

$keywords = "foo";
$data = "This is a lower foo. This is an upper FOO. This is a ucase Foo";

$lower = strtolower($keywords);
$upper = strtoupper($keywords);
$ucase = ucwords($keywords);
$words = array($lower, $upper, $ucase);

while ( list($key, $val) = each($words) ) {
print("key: $key = val: $valbr");
$hilite = "font color=\"#ff\"" . $val . "/font";
$replaced[] = ereg_replace($val, $hilite, $data);
}
for($i=0;$isizeof($replaced);$i++) {
echo $replaced[$i]."br";
}

The first print statement will show you what keywords we are
focusing on. The ereg_replace in this case is appending an arrary.
If you then walk that array, you will see that each of your keywords
was matched and highlited.  

that should get you a little further along.

Jeff


 G'day PHP'ers
 
 I am trying highlight the results from a search, so far I have this
 working but only if the string is an exact match ie: case sensitive, for
 example:
 
 ?php
 $keywords = "foo";
 $data = "This is a lower foo. This is an upper FOO. This is a ucase
 Foo";
 
 $lower = strtolower($keywords);
 $upper = strtoupper($keywords);
 $ucase = ucwords($keywords);
 $words = array($lower, $upper, $ucase);
 
 while ( list($key, $val) = each($words) ) {
 $hilite = "font color=\"#ff\"" . $val . "/font";
 $replaced = ereg_replace($val, $hilite, $data);
 }
 
 echo $replaced;
 ?
 
 Now as metioned this seems to work only for "foo" does anyone have any
 idea why? 
 
 Also I need to be able to support mutiple keywords ie: foo Foo FOO, so
 basically I know I could split(" ", $keywords) then some how traverse
 the array making a new array of all possible case combinations then in
 my while loop replace each occurance found in $data with the highlighted
 replacment, sounds easy hmm
 
 If anyone has any ideas or can see what I am doing wrong so far, it
 would be mutch appreciated.
 
 Regards,
 
 Joseph
 


-- 
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]