473,513 Members | 4,022 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

str_ireplace() for php4?

Hi,

would anybody have a version of str_irepalce(),
(http://uk.php.net/manual/en/function.str-ireplace.php) for php4?

The doc mentions eregi_replace() and preg_repalce() but I cannot get my head
around it.

Would anybody have a few lines of code that would reproduce the
functionality above.

What I actually need to do is a search an replace of a web address.

Simon
Mar 11 '06 #1
8 5557
Simon wrote:
would anybody have a version of str_irepalce(),
(http://uk.php.net/manual/en/function.str-ireplace.php) for php4?

The doc mentions eregi_replace() and preg_repalce() but I cannot get
my head around it.


if (!function_exists('str_ireplace')) {
function str_ireplace($needle, $str, $haystack) {
return preg_replace("/$needle/i", $str, $haystack);
}
}
JW
Mar 11 '06 #2
> Simon wrote:
would anybody have a version of str_irepalce(),
(http://uk.php.net/manual/en/function.str-ireplace.php) for php4?

The doc mentions eregi_replace() and preg_repalce() but I cannot get
my head around it.


if (!function_exists('str_ireplace')) {
function str_ireplace($needle, $str, $haystack) {
return preg_replace("/$needle/i", $str, $haystack);
}
}


Thanks!

Just out of curiosity, would it work if $needle, $str, $haystack had
escape/special characters?

Simon
Mar 11 '06 #3
Simon wrote:
Just out of curiosity, would it work if $needle, $str, $haystack had
escape/special characters?


Good point. You need to escape reserved regular expression characters in
$needle as follows:

if (!function_exists('str_ireplace')) {
function str_ireplace($needle, $str, $haystack) {
$needle = preg_quote($needle, '/');
return preg_replace("/$needle/i", $str, $haystack);
}
}

$str and $haystack do not need to be modified.
JW
Mar 11 '06 #4

Simon wrote:
Hi,

would anybody have a version of str_irepalce(),
(http://uk.php.net/manual/en/function.str-ireplace.php) for php4?

The doc mentions eregi_replace() and preg_repalce() but I cannot get my head
around it.

Would anybody have a few lines of code that would reproduce the
functionality above.

What I actually need to do is a search an replace of a web address.

Simon


Just grab the function from PEAR::PHP_Compat
(http://pear.php.net/package/PHP_Compat/).

Mar 11 '06 #5
Janwillem Borleffs wrote:
Simon wrote:
Just out of curiosity, would it work if $needle, $str, $haystack had
escape/special characters?


Good point. You need to escape reserved regular expression characters in
$needle as follows:

if (!function_exists('str_ireplace')) {
function str_ireplace($needle, $str, $haystack) {
$needle = preg_quote($needle, '/');
return preg_replace("/$needle/i", $str, $haystack);
}
}

$str and $haystack do not need to be modified.


What if $str contained "\1"?

--
Toby A Inkster BSc (Hons) ARCS
Contact Me ~ http://tobyinkster.co.uk/contact

Mar 12 '06 #6
Toby Inkster wrote:
What if $str contained "\1"?


You probably mean "\\1", which will contain pattern matches grouped by
parenthesis, but these will be ignored as preg_quote is used to escape the
parenthesis when occurring in $needle.
JW
Mar 12 '06 #7

Janwillem Borleffs wrote:
Toby Inkster wrote:
What if $str contained "\1"?


You probably mean "\\1", which will contain pattern matches grouped by
parenthesis, but these will be ignored as preg_quote is used to escape the
parenthesis when occurring in $needle.


Actually, \1 would end up being an empty string if the pattern doesn't
specify capturing.

Mar 12 '06 #8
>>
Simon


Just grab the function from PEAR::PHP_Compat
(http://pear.php.net/package/PHP_Compat/).


That's great, didn't know it existed.

Thanks for that.

Simon
Mar 12 '06 #9

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

Similar topics

0
2443
by: Nisha_tm | last post by:
Hello: I have a form in which I have checkboxes. Right now, I wrote the form's html and the php4 script. I use associative arrays in the form to capture the checkboxes that are checked. My html form puts the data in $info if the check box is checked. Part of my php4 script is as follows:
0
2035
by: Klaus Boehmer | last post by:
Hello, I'm trying to install gd2 with gif-support as an extension with php4. I compiled the patched version of gd2 - fine. I compiled php4 with gd=shared - fine. I installed it and restarted apache and I get: undefined symbol: gdImagePngCtx I recompiled php4 and included gd and everything works fine. But as soon as I compile gd2 as shared...
5
2776
by: Tim Tyler | last post by:
I'm sure this is a FAQ - but I could not find a coherent statement of the answer: Some of my clients want PHP4. Other ones want PHP5. Can I run both PHP4 and PHP5 under the same instance of Apache - both on port 80 - using different file extensions to distinguish between them? --
2
1573
by: windandwaves | last post by:
Does anyone know of a function that works like str_ireplace in PHP < 5? str_ireplace(a,b,c) replaces a with b in c, just like str_replace, but case insensitive. TIA - Nicolaas
2
2575
by: Stefan Huber | last post by:
Hi I've got a really strange problem, and can't find out why it's not working as intended. in order to use php4 and 5 together on a webserver and the requirement for running as different users, I use suexec and a wrapper script for php files. to make it a bit clearer, i'll post the different snippets: httpd.conf:
12
2280
by: Drazen Gemic | last post by:
How long will PHP4 be supported ? When is PHP4 end of life scheduled ? DG
3
2936
by: doctorhardik | last post by:
hai all i am try configure php4.3.9 on my FC-3 machine. and my mysql database version 5.0.1, in phpinfo file it show mysql but when i run php -v command it show error like
8
2300
by: FFMG | last post by:
Hi, I am slowly moving my code to php5. But I would like to make it backward compatible in case something bad happens, (and to make sure I understand what the changes are). The way the constructors work seem to have changed quite a bit and I am not getting the same behavior across the versions. // Some simple code/
1
2568
by: AAGazer | last post by:
Hi, For some reason str_ireplace and str_replace do not remove the euro symbol. This is the code snip it: $mremoveArray=array("€","£"); $tString=”15,00€”; $pa=str_ireplace($mremoveArray,'',$tString); The pound sign is removed but not the euro.
0
7270
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7397
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. ...
0
7563
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7125
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
7543
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5102
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4757
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...
0
3239
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
470
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...

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.