473,811 Members | 2,714 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 1979
On Nov 3, 10:30*am, Bob <b...@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));

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******** *************** ***********@w1g 2000prk.googleg roups.com:
On Nov 3, 10:30*am, Bob <b...@nospam.nl wrote:
>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******** *************** ***********@w1g 2000prk.googleg roups.com:
>On Nov 3, 10:30 am, Bob <b...@nospam.nl wrote:
>>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('A BC','<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************ *************** *************** @spamyourself.c omwrote in
news:49******** *************@n ews.xs4all.nl:
Bob schreef:
>Alex Eiswirth <Al***********@ gmail.comwrote in
news:93******* *************** ************@w1 g2000prk.google groups.com:
>>On Nov 3, 10:30 am, Bob <b...@nospam.nl wrote:
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('A BC','<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="<fon t color=\"red\">$ keyword</font>";

$occasion = (ereg_replace($ keyword,$bkeywo rd,$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('si g.invalid', 'gmail.com', $from);
Nov 3 '08 #6
Bob schreef:
Erwin Moller
<Si************ *************** *************** @spamyourself.c omwrote in
news:49******** *************@n ews.xs4all.nl:
>Bob schreef:
>>Alex Eiswirth <Al***********@ gmail.comwrote in
news:93****** *************** *************@w 1g2000prk.googl egroups.com:

On Nov 3, 10:30 am, Bob <b...@nospam.nl wrote:
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('A BC','<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="<fon t color=\"red\">$ keyword</font>";

$occasion = (ereg_replace($ keyword,$bkeywo rd,$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.inv alidwrote 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="<fon t color=\"red\">$ keyword</font>";

$occasion = (ereg_replace($ keyword,$bkeywo rd,$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*******@attgl obal.net
=============== ===

Nov 3 '08 #9
On Mon, 3 Nov 2008 12:48:55 GMT, bo*@nospam.nl wrote:
Curtis <dy****@sig.inv alidwrote 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="<fon t color=\"red\">$ keyword</font>";

$occasion = (ereg_replace($ keyword,$bkeywo rd,$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($_PO ST['text']) . '</b>';

--
Curtis
$email = str_replace('si g.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
2383
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 found. $qs and $clean_qs produce the same results. Also, can someone who is fluent with regex stuff take a look at my eregi expressions ? Im not sure if this is the most efficient way of
4
4691
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 queries. I'd like help if possible in formatting one of the values it returns.
1
1700
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
1160
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, $item); This successfully replaces all occurences of $search_string.
6
2496
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
10306
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 ) { if ( ( singlecharacter >= 'A' ) && ( singlecharacter <= 'Z' ) ) { // returning the uppercase version here } else
15
7047
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
1825
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
1334
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:- http://www.nowhere.co.uk/apage.htm which would display 'http://www.nowhere.co.uk/apage.htm' as the link text or
0
9605
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10647
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9204
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6889
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5554
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4339
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3017
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.