Connecting Tech Pros Worldwide Help | Site Map

eregi_replace returns only lowercase

Bob
Guest
 
Posts: n/a
#1: Nov 3 '08
Hi,

Maybe this problem has already been mentionned, but I am new to this group,
so here we go.

$string = "This is for ABC only"

$new = (eregi_replace('ABC','<b>ABC</b>',$string));

print $new geeft nu
This is for <b>abc</bonly
where I would like to see 'abc' in uppercase. I have searched the internet
for the solution, consulted several PHP books, but can not find the
solution. Can anyone help? Thanks.

Bob
Alex Eiswirth
Guest
 
Posts: n/a
#2: Nov 3 '08

re: eregi_replace returns only lowercase


On Nov 3, 10:30*am, Bob <b...@nospam.nlwrote:
Quote:
Hi,
>
Maybe this problem has already been mentionned, but I am new to this group,
so here we go.
>
$string = "This is for ABC only"
>
$new = (eregi_replace('ABC','<b>ABC</b>',$string));
>
print $new geeft nu
This is for <b>abc</bonly
where I would like to see 'abc' in uppercase. I have searched the internet
for the solution, consulted several PHP books, but can not find the
solution. Can anyone help? Thanks.
>
Bob

Hi Bob,

use ereg_replace instead of eregi_replace.
This function is identical to ereg_replace() except that this ignores
case distinction when matching alphabetic characters.

Alex Eiswirth http://www.eiswirth.de
Bob
Guest
 
Posts: n/a
#3: Nov 3 '08

re: eregi_replace returns only lowercase


Alex Eiswirth <Alex.Eiswirth@gmail.comwrote in
news:937a06ac-e448-4a2e-9587-15a3bbca1ebc@w1g2000prk.googlegroups.com:
Quote:
On Nov 3, 10:30*am, Bob <b...@nospam.nlwrote:
Quote:
>Hi,
>>
>Maybe this problem has already been mentionned, but I am new to this
>grou
p,
Quote:
>so here we go.
>>
>$string = "This is for ABC only"
>>
>$new = (eregi_replace('ABC','<b>ABC</b>',$string));
>>
>print $new geeft nu
>This is for <b>abc</bonly
>where I would like to see 'abc' in uppercase. I have searched the
>interne
t
Quote:
>for the solution, consulted several PHP books, but can not find the
>solution. Can anyone help? Thanks.
>>
>Bob
>
>
Hi Bob,
>
use ereg_replace instead of eregi_replace.
This function is identical to ereg_replace() except that this ignores
case distinction when matching alphabetic characters.
>
Alex Eiswirth http://www.eiswirth.de
>
ereg or eregi makes no difference in the output. In both cases it returns
in lowercase.

Bob.
Erwin Moller
Guest
 
Posts: n/a
#4: Nov 3 '08

re: eregi_replace returns only lowercase


Bob schreef:
Quote:
Alex Eiswirth <Alex.Eiswirth@gmail.comwrote in
news:937a06ac-e448-4a2e-9587-15a3bbca1ebc@w1g2000prk.googlegroups.com:
>
Quote:
>On Nov 3, 10:30 am, Bob <b...@nospam.nlwrote:
Quote:
>>Hi,
>>>
>>Maybe this problem has already been mentionned, but I am new to this
>>grou
>p,
Quote:
>>so here we go.
>>>
>>$string = "This is for ABC only"
>>>
>>$new = (eregi_replace('ABC','<b>ABC</b>',$string));
>>>
>>print $new geeft nu
>>This is for <b>abc</bonly
>>where I would like to see 'abc' in uppercase. I have searched the
>>interne
>t
Quote:
>>for the solution, consulted several PHP books, but can not find the
>>solution. Can anyone help? Thanks.
>>>
>>Bob
>>
>Hi Bob,
>>
>use ereg_replace instead of eregi_replace.
>This function is identical to ereg_replace() except that this ignores
>case distinction when matching alphabetic characters.
>>
>Alex Eiswirth http://www.eiswirth.de
>>
>
ereg or eregi makes no difference in the output. In both cases it returns
in lowercase.
Over here:
$string = "This is for ABC only";
echo eregi_replace('ABC','<b>ABC</b>',$string);
gives:
This is for <b>ABC</bonly

AND
$string = "This is for ABC only";
echo ereg_replace('ABC','<b>ABC</b>',$string);
gives:
This is for <b>ABC</bonly

Could you confirm this on your system Bob?
Just use THIS simple codefragmet, and leave the rest of your code out.

Regards,
Erwin Moller
Quote:
>
Bob.

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
Bob
Guest
 
Posts: n/a
#5: Nov 3 '08

re: eregi_replace returns only lowercase


Erwin Moller
<Since_humans_read_this_I_am_spammed_too_much@spam yourself.comwrote in
news:490ece9d$0$184$e4fe514c@news.xs4all.nl:
Quote:
Bob schreef:
Quote:
>Alex Eiswirth <Alex.Eiswirth@gmail.comwrote in
>news:937a06ac-e448-4a2e-9587-15a3bbca1ebc@w1g2000prk.googlegroups.com:
>>
Quote:
>>On Nov 3, 10:30 am, Bob <b...@nospam.nlwrote:
>>>Hi,
>>>>
>>>Maybe this problem has already been mentionned, but I am new to
>>>this grou
>>p,
>>>so here we go.
>>>>
>>>$string = "This is for ABC only"
>>>>
>>>$new = (eregi_replace('ABC','<b>ABC</b>',$string));
>>>>
>>>print $new geeft nu
>>>This is for <b>abc</bonly
>>>where I would like to see 'abc' in uppercase. I have searched the
>>>interne
>>t
>>>for the solution, consulted several PHP books, but can not find the
>>>solution. Can anyone help? Thanks.
>>>>
>>>Bob
>>>
>>Hi Bob,
>>>
>>use ereg_replace instead of eregi_replace.
>>This function is identical to ereg_replace() except that this
>>ignores case distinction when matching alphabetic characters.
>>>
>>Alex Eiswirth http://www.eiswirth.de
>>>
>>
>ereg or eregi makes no difference in the output. In both cases it
>returns in lowercase.
>
Over here:
$string = "This is for ABC only";
echo eregi_replace('ABC','<b>ABC</b>',$string);
gives:
This is for <b>ABC</bonly
>
AND
$string = "This is for ABC only";
echo ereg_replace('ABC','<b>ABC</b>',$string);
gives:
This is for <b>ABC</bonly
>
Could you confirm this on your system Bob?
Just use THIS simple codefragmet, and leave the rest of your code out.
>
Regards,
Erwin Moller
>
Quote:
>>
>Bob.
>
>
Hi Erwin (and others),

You are right, my question in the first place was incorrect. I tried to
keep the problem short, but that corrupted the question.

In my example 'ABC' is actually a variable which is filled in by a user
in a form. When he fills in 'abc' (lowercase, what most people do with
key-words) php returns with 'abc'. When he fills in 'aBc' php returns
with 'aBc' etc. Thus, the problem is, that I don't want to care how the
user fills in (upper- or lowercase), but I want php to return the
original value. Hope this makes the problem more clear.

Part of my script is:

$bkeyword="<font color=\"red\">$keyword</font>";

$occasion = (ereg_replace($keyword,$bkeyword,$occasion));

Bob.
Curtis
Guest
 
Posts: n/a
#6: Nov 3 '08

re: eregi_replace returns only lowercase


On Mon, 3 Nov 2008 09:30:26 GMT, bob@nospam.nl wrote:
Quote:
Hi,
>
Maybe this problem has already been mentionned, but I am new to this group,
so here we go.
>
$string = "This is for ABC only"
>
$new = (eregi_replace('ABC','<b>ABC</b>',$string));
The parentheses starting at "(eregi..." are unnecessary.
Quote:
print $new geeft nu
This is for <b>abc</bonly
where I would like to see 'abc' in uppercase. I have searched the internet
for the solution, consulted several PHP books, but can not find the
solution. Can anyone help? Thanks.
>
Bob
Just a heads-up: don't use the POSIX regexes (ereg_*), the PCRE regex
engine (preg_*) is faster, and has more features. The POSIX
functions aren't binary safe, either.

Are you sure you even need regex here? See:

<URL:http://php.net/str_ireplace>

Since you are hard coding "ABC" into the replacement argument,
there's no reason your result shouldn't also contain the capitalized
"ABC". If you need to operate on grouped matches in your replacement
string, use preg_replace() with the "/e" modifier.

<URL:http://php.net/manual/en/function.preg-replace.php(See example
#4.)

We would need to see some of the actual data with which you're
working to be able to help more completely.

--
Curtis
$email = str_replace('sig.invalid', 'gmail.com', $from);
Erwin Moller
Guest
 
Posts: n/a
#7: Nov 3 '08

re: eregi_replace returns only lowercase


Bob schreef:
Quote:
Erwin Moller
<Since_humans_read_this_I_am_spammed_too_much@spam yourself.comwrote in
news:490ece9d$0$184$e4fe514c@news.xs4all.nl:
>
Quote:
>Bob schreef:
Quote:
>>Alex Eiswirth <Alex.Eiswirth@gmail.comwrote in
>>news:937a06ac-e448-4a2e-9587-15a3bbca1ebc@w1g2000prk.googlegroups.com:
>>>
>>>On Nov 3, 10:30 am, Bob <b...@nospam.nlwrote:
>>>>Hi,
>>>>>
>>>>Maybe this problem has already been mentionned, but I am new to
>>>>this grou
>>>p,
>>>>so here we go.
>>>>>
>>>>$string = "This is for ABC only"
>>>>>
>>>>$new = (eregi_replace('ABC','<b>ABC</b>',$string));
>>>>>
>>>>print $new geeft nu
>>>>This is for <b>abc</bonly
>>>>where I would like to see 'abc' in uppercase. I have searched the
>>>>interne
>>>t
>>>>for the solution, consulted several PHP books, but can not find the
>>>>solution. Can anyone help? Thanks.
>>>>>
>>>>Bob
>>>Hi Bob,
>>>>
>>>use ereg_replace instead of eregi_replace.
>>>This function is identical to ereg_replace() except that this
>>>ignores case distinction when matching alphabetic characters.
>>>>
>>>Alex Eiswirth http://www.eiswirth.de
>>>>
>>ereg or eregi makes no difference in the output. In both cases it
>>returns in lowercase.
>Over here:
>$string = "This is for ABC only";
>echo eregi_replace('ABC','<b>ABC</b>',$string);
>gives:
>This is for <b>ABC</bonly
>>
>AND
>$string = "This is for ABC only";
>echo ereg_replace('ABC','<b>ABC</b>',$string);
>gives:
>This is for <b>ABC</bonly
>>
>Could you confirm this on your system Bob?
>Just use THIS simple codefragmet, and leave the rest of your code out.
>>
>Regards,
>Erwin Moller
>>
Quote:
>>Bob.
>>
>
Hi Erwin (and others),
>
You are right, my question in the first place was incorrect. I tried to
keep the problem short, but that corrupted the question.
>
In my example 'ABC' is actually a variable which is filled in by a user
in a form. When he fills in 'abc' (lowercase, what most people do with
key-words) php returns with 'abc'. When he fills in 'aBc' php returns
with 'aBc' etc. Thus, the problem is, that I don't want to care how the
user fills in (upper- or lowercase), but I want php to return the
original value. Hope this makes the problem more clear.
>
Part of my script is:
>
$bkeyword="<font color=\"red\">$keyword</font>";
>
$occasion = (ereg_replace($keyword,$bkeyword,$occasion));
>
Bob.
Here is an example.

$string = "This is for AbC only";
echo eregi_replace('(ABC)','<b>\\1</b>',$string);

Read more here about \\1:
http://nl3.php.net/manual/en/function.eregi-replace.php

Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
Bob
Guest
 
Posts: n/a
#8: Nov 3 '08

re: eregi_replace returns only lowercase


Curtis <dyer85@sig.invalidwrote in
news:MPG.237878837ecb0d44989687@news.verizon.net:
Quote:
On Mon, 3 Nov 2008 09:30:26 GMT, bob@nospam.nl wrote:
Quote:
>Hi,
>>
>Maybe this problem has already been mentionned, but I am new to this
>group, so here we go.
>>
>$string = "This is for ABC only"
>>
>$new = (eregi_replace('ABC','<b>ABC</b>',$string));
>
The parentheses starting at "(eregi..." are unnecessary.
>
Quote:
>print $new geeft nu
>This is for <b>abc</bonly
>where I would like to see 'abc' in uppercase. I have searched the
>internet for the solution, consulted several PHP books, but can not
>find the solution. Can anyone help? Thanks.
>>
>Bob
>
Just a heads-up: don't use the POSIX regexes (ereg_*), the PCRE regex
engine (preg_*) is faster, and has more features. The POSIX
functions aren't binary safe, either.
>
Are you sure you even need regex here? See:
>
<URL:http://php.net/str_ireplace>
>
Since you are hard coding "ABC" into the replacement argument,
there's no reason your result shouldn't also contain the capitalized
"ABC". If you need to operate on grouped matches in your replacement
string, use preg_replace() with the "/e" modifier.
>
<URL:http://php.net/manual/en/function.preg-replace.php(See example
#4.)
>
We would need to see some of the actual data with which you're
working to be able to help more completely.
>
Hi Curtis,

In a previous posting I explain that my question in the first place
wasn't correct. Maybe this is better:

In my example 'ABC' is actually a variable which is filled in by a user
in a form. When he fills in 'abc' (lowercase, what most people do with
key-words) php returns with 'abc'. When he fills in 'aBc' php returns
with 'aBc' etc. Thus, the problem is, that I don't want to care how the
user fills in (upper- or lowercase), but I want php to return the
original value. Hope this makes the problem more clear.

Part of my script is:

$bkeyword="<font color=\"red\">$keyword</font>";

$occasion = (ereg_replace($keyword,$bkeyword,$occasion));
Jerry Stuckle
Guest
 
Posts: n/a
#9: Nov 3 '08

re: eregi_replace returns only lowercase


Bob wrote:
Quote:
Hi,
>
Maybe this problem has already been mentionned, but I am new to this group,
so here we go.
>
$string = "This is for ABC only"
>
$new = (eregi_replace('ABC','<b>ABC</b>',$string));
>
print $new geeft nu
This is for <b>abc</bonly
where I would like to see 'abc' in uppercase. I have searched the internet
for the solution, consulted several PHP books, but can not find the
solution. Can anyone help? Thanks.
>
Bob
>
A regex is way overkill in this case. Just concatenate <band </b>
before and after your user input, i.e. (in another post you indicate
this is user input):

$new = "<br>{$POST['user_field']}.<br>";

Or, if you prefer,

$new = '<br>' . $POST['user_field'] . '<br>';

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Curtis
Guest
 
Posts: n/a
#10: Nov 4 '08

re: eregi_replace returns only lowercase


On Mon, 3 Nov 2008 12:48:55 GMT, bob@nospam.nl wrote:
Quote:
Curtis <dyer85@sig.invalidwrote in
news:MPG.237878837ecb0d44989687@news.verizon.net:
>
Quote:
On Mon, 3 Nov 2008 09:30:26 GMT, bob@nospam.nl wrote:
Quote:
Hi,
>
Maybe this problem has already been mentionned, but I am new to this
group, so here we go.
>
$string = "This is for ABC only"
>
$new = (eregi_replace('ABC','<b>ABC</b>',$string));
The parentheses starting at "(eregi..." are unnecessary.
Quote:
print $new geeft nu
This is for <b>abc</bonly
where I would like to see 'abc' in uppercase. I have searched the
internet for the solution, consulted several PHP books, but can not
find the solution. Can anyone help? Thanks.
>
Bob
Just a heads-up: don't use the POSIX regexes (ereg_*), the PCRE regex
engine (preg_*) is faster, and has more features. The POSIX
functions aren't binary safe, either.

Are you sure you even need regex here? See:

<URL:http://php.net/str_ireplace>

Since you are hard coding "ABC" into the replacement argument,
there's no reason your result shouldn't also contain the capitalized
"ABC". If you need to operate on grouped matches in your replacement
string, use preg_replace() with the "/e" modifier.

<URL:http://php.net/manual/en/function.preg-replace.php(See example
#4.)

We would need to see some of the actual data with which you're
working to be able to help more completely.
>
Hi Curtis,
>
In a previous posting I explain that my question in the first place
wasn't correct. Maybe this is better:
>
In my example 'ABC' is actually a variable which is filled in by a user
in a form. When he fills in 'abc' (lowercase, what most people do with
key-words) php returns with 'abc'. When he fills in 'aBc' php returns
with 'aBc' etc. Thus, the problem is, that I don't want to care how the
user fills in (upper- or lowercase), but I want php to return the
original value. Hope this makes the problem more clear.
>
Part of my script is:
>
$bkeyword="<font color=\"red\">$keyword</font>";
>
$occasion = (ereg_replace($keyword,$bkeyword,$occasion));
Yes, chalk it up to a late night or maybe getting used to Gravity. I
didn't realize additional posts had been made in the thread.

I would have to agree with Jerry's method recently posted. If you
don't need to parse the text to see what you want to wrap the user
text in, regexes are unnecessary.

// assuming isset($_POST['text'])
$bold = '<b>' . strtoupper($_POST['text']) . '</b>';

--
Curtis
$email = str_replace('sig.invalid', 'gmail.com', $from);
Closed Thread