Jump to content

Preg_Match change " to * from searchbox


chewbears

Recommended Posts

So I have a search function (part posted below).  I have it set up that a user passes asterisk in the way that quotes would work in a normal search function.  Due to the scope of the search function a pagination function can not handle quotes because it breaks the html.  So what I need to do is transform the quotes a user would type into the search box into asterisks so the function will handle everything.  I am assuming this is done with preg_match, but I am not familiar with preg_match at all other then what is written in manuals. 

 

 

<?php
$arr['searchterms'] = trim($arr['searchterms']); 

if (strstr($arr['searchterms'],'*+'))
{
$terms = explode('*+*',substr($arr['searchterms'],1,-1));
$case = "AND";
}
else if (strstr($arr['searchterms'],'*'))
{
$terms = explode('* *',substr($arr['searchterms'],1,-1)); 
$case = " OR";
}
else 
{
$terms = explode(" ",$arr['searchterms']);
$case = " OR";
}

?>

Link to comment
Share on other sites

Edit: LOL, duplicate information from above ^^^

 

pagination function can not handle quotes because it breaks the html

 

^^^ Not if you use htmlentities(), with the second parameter set to ENT_QUOTES, on DATA being output to the browser that could contain HTML special characters and/or use urlencode() if this is going into a URL.

 

What are you actually doing at the point that the HTML gets broken by a ' ?

 

Link to comment
Share on other sites

The above does not break only when I switch the * to a double qoute ".

 

I can not str_replace because searchterms is not a global variable so when the pagination goes to get it it uses a get and does not look at what has been done to the searchterms in the search function.  Kinda not smart coding but it works for the time being.  Htmlenties may work but I am not sure how to use it within the get of the pagination builder.  Working on that now.

Link to comment
Share on other sites

htmlentities doesn't work as it breaks the search as it passes the qoutes properly, which I need to drop in order for the string to exist in the database.  Because I do not have "Big Bend".  I have Big Bend in a field.  So the Query before passed %'big bend'% with the htmlentities it passes %"big bend"%

Link to comment
Share on other sites

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.