/    Sign up×
Community /Pin to ProfileBookmark

Having troubles using "str_ireplace"

I am having problems with the str_ireplace() function. I know how it works, I’ve it in been using it in the past, but for some reason things aren’t working now, and I can’t find out why.

The URL of the page I made is here: http://zigweb.net/Site/Shared/Quotes/STRREP.PHP?QID={1.816.2.6}&QCat={816}&QType={2}.

I have been getting the value of QID through $_GET() That works fine, and I can echo it onto the page, it will display {1.816.2.6} just like it’s supposed to.

Then I tried to implement a replace function to strip the { } tags. First it looked like this:

[CODE]
<?php
$QID = $_GET[“QID”];
echo “$QID<br />”;
$Brackets=array(“{“,”}”);
$Strip=””;
$Q=str_ireplace($Brackets,$Strip,$QID);
echo “$Q<br />”;
?>
[/CODE]

This would kill my script, and my page would be blank.

So I tried just a basic replace() function, copied and pasted straight from W3Schools examples, so I KNOW it is 100% correct script syntax.

The full src of the PHP file looks like this:

[CODE]
<?php
echo str_ireplace(“WORLD”,”Peter”,”Hello world!”);
?>[/CODE]

This shows up as a blank page on my browser when it should show up as “Hello Peter!”

What’s going on? Why does all my other PHP stuff work, but not ireplace()?

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@andre4s_yFeb 09.2008 — this script :
[code=php]
<?php
$QID = $_GET["QID"];
echo "$QID<br />";
$Brackets=array("{","}");
$Strip="";
$Q=str_ireplace($Brackets,$Strip,$QID);
echo "$Q<br />";
?>
[/code]

works fine with me...

I test it with this url : http://localhost/php/idphp/REGEX11.PHP?QID={1.816.2.6}&QCat={816}&QType={2}

No problemo.. maybe it is not the hotspot... :-??
Copy linkTweet thisAlerts:
@ZackemoauthorFeb 09.2008 — Hot Spot?

As in the place where the error is?

I know it has to be. Originally I figured this too, so I //ignored every other line of my script except those ones. Then when it still failed, I tried making it's own script/page solely devoted to that, and to the example I pasted from W3Schools.

Unless by Hotspot you mean something else?

Is it possible the PHP system/server stuff for my webhosting company is not complete, and it's not recognizing str_ireplace() as a function?

*Or* is there an error handler script I could write to determine where my script is failing and why? How would I go about writing such a code, if so?
Copy linkTweet thisAlerts:
@andre4s_yFeb 09.2008 — Yup...

my friend and me usually say where the errors located as "hotspot"..

maybe str_replace works??

What version is your php in your webhosting???

try this :
[code=php]
if(!function_exists('str_ireplace')) {
function str_ireplace($search,$replace,$subject) {
$search = preg_quote($search, "/");
return preg_replace("/".$search."/i", $replace, $subject); } }
[/code]
×

Success!

Help @Zackemo spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.28,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...