Jump to content

Recommended Posts

I've tried to handle this a few ways, and none of them seem to work.

 

Warning: preg_replace() [function.preg-replace]: Empty regular expression in /home/content/index.php on line 32

 

$_SESSION['keywords'] = get_search_phrase($_SERVER["HTTP_REFERER"]);
$key = $_SESSION['keywords'];
if (empty($key)) {
$key = "nokeywords";
}
$words = preg_replace(" ", "0", $key); //replace any spaces with "0".

 

Now I've also tried it this way....

 

$_SESSION['keywords'] = get_search_phrase($_SERVER["HTTP_REFERER"]);
$key = $_SESSION['keywords'];
if ($key == "") {
$key = "nokeywords";
}
elseif ($key == NULL) {
        $key = "nullkeywords";
}
$words = preg_replace(" ", "0", $key); //replace any spaces with "0".

 

Neither one worked...

 

Maybe there's an easier way to do it? What I'm actually trying to accomplish is to strip out ANY character in the variable that is not alpha/numeric. I only want numbers and letters in the strings. I know I'm only currently going after spaces, but maybe there's an easier function to accomplish this that I'm unaware of.

 

Thanks for your input in advance.

Link to comment
https://forums.phpfreaks.com/topic/151729-solved-preg_replace-empty/
Share on other sites

Thanks, I made that change, and I understand you're exactly right.

 

Now is there a way I can parse through the string and remove any characters that are NOT alpha/numeric?

 

I've using this value to pass a variable in the hyperlink, and if any characters other than letters or numbers appear, the whole string is simply ignored.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.