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 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
> 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
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
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/).
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
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
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. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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:
|
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...
|
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?
--
|
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
|
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:
| |
by: Drazen Gemic |
last post by:
How long will PHP4 be supported ? When is PHP4 end of life scheduled ?
DG
|
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
|
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/
|
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.
|
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...
|
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. ...
| |
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...
|
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...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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...
| |