473,509 Members | 2,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

eregi_replace returns only lowercase

Bob
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
Nov 3 '08 #1
9 1959
On Nov 3, 10:30*am, Bob <b...@nospam.nlwrote:
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
Nov 3 '08 #2
Bob
Alex Eiswirth <Al***********@gmail.comwrote in
news:93**********************************@w1g2000p rk.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.

Bob.
Nov 3 '08 #3
Bob schreef:
Alex Eiswirth <Al***********@gmail.comwrote in
news:93**********************************@w1g2000p rk.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
>
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
Nov 3 '08 #4
Bob
Erwin Moller
<Si******************************************@spam yourself.comwrote in
news:49*********************@news.xs4all.nl:
Bob schreef:
>Alex Eiswirth <Al***********@gmail.comwrote in
news:93**********************************@w1g2000 prk.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
>>
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.
Nov 3 '08 #5
On Mon, 3 Nov 2008 09:30:26 GMT, bo*@nospam.nl wrote:
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.
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);
Nov 3 '08 #6
Bob schreef:
Erwin Moller
<Si******************************************@spam yourself.comwrote in
news:49*********************@news.xs4all.nl:
>Bob schreef:
>>Alex Eiswirth <Al***********@gmail.comwrote in
news:93**********************************@w1g200 0prk.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
>>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
Nov 3 '08 #7
Bob
Curtis <dy****@sig.invalidwrote in
news:MP************************@news.verizon.net:
On Mon, 3 Nov 2008 09:30:26 GMT, bo*@nospam.nl wrote:
>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.
>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));
Nov 3 '08 #8
Bob wrote:
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.
js*******@attglobal.net
==================

Nov 3 '08 #9
On Mon, 3 Nov 2008 12:48:55 GMT, bo*@nospam.nl wrote:
Curtis <dy****@sig.invalidwrote in
news:MP************************@news.verizon.net:
On Mon, 3 Nov 2008 09:30:26 GMT, bo*@nospam.nl wrote:
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.
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);
Nov 4 '08 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
2371
by: fartsniff | last post by:
Hello all. I am starting to work on a URL "cleaner" of sorts. The code below is only checking for a few simple entries on the URL, but for some reason it is not replacing them with "" when...
4
4673
by: David | last post by:
Hi, I've had a search through google but couldn't really find the answer I was looking for.I'm new to PHP, so please take it <relatively> easy. I've created a script which runs some SNMP...
1
1689
by: Florian Leeber | last post by:
Hi! I try to: function do_bug_link($in) { return eregi_replace("\!(+)","<a href='bug.php?op=show&bugid=\\1'>Bug \\1</a>",$in); }
2
1145
by: saiena | last post by:
Is there a way in my regular expression syntax to cause alternating occurences of the search string to be replaced? Here's my code: $item = eregi_replace($search_string, $replace_string,...
6
2474
by: Krij | last post by:
Hi! I wonder: is '<SCRIPT TYPE="TEXT/JAVASCRIPT1.2">' a correct way of starting? Or should it be kept in lowercase?
2
10283
by: evantri | last post by:
Hi everyone, I am required to write a standard C function to import the single character variable and return the lowercase version of the character int upper_to_lower ( char singlecharacter ) {...
15
6985
by: Optimus | last post by:
I would like to know if there is a encryption algorithm that returns only lowercase encrypted string. Thanks in advance.
1
1804
by: gsreenathreddy | last post by:
Hi! <html> <head> <script type="text/javascript"> function upperCase() { var x=document.getElementById("fname").value; document.getElementById("fname").value=x.toUpperCase(); }
2
1323
by: Mad Hatter | last post by:
Hi I'm having problems getting my head around eregi_replace. What I want to do is allow users to enter links to their sites in a simple guest book. The links can take either of 2 formats:- ...
0
7233
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7135
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7342
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7410
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7505
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5650
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
3215
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
1
774
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
440
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.