Hello, I am using str_replace to change spaces into a % for a mysql query. I am having a weird error sometimes where it gives me a � character and do not know why. any ideas? I search crying babies and i get: crying�bies (error) I search crying mice and i get: crying mice (correct) this is my code: //Takes spaces and adds wildcard $search = array(' '); $replace = array('%'); $subject = $SearchText; $SearchText = str_replace($search, $replace, $subject); It only happens for certain words... Thank You, -Tim
Try this instead: $searchText = preg_replace('/\s+/u', '%', $searchText); PHP: Not sure if it'll actually work though.. Just a test.
are you sure that this are the full arrays? $search = array(' '); $replace = array('%'); or are there some other strings in the array too? or is only this one in it?
Think this is a problem with the content type. try changing it in your meta <meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
ALMOST!!!! this is what happens now... "construction delays" turns into "constructionÞlays" are there any other options i could try? I have no idea why this is happening i don't thin i am doing anything different.
you say this is coming from your database right? Do you have any special encoding on your DB charset?
this is what i have: squery varchar(255) latin1_swedish_ci (this was default) --- thanks for your help so far by the way!
can you paste the full code from the start of you modifying the search string to the mysql_query line please
sure thing: $Query = $_POST['Query']; $query1= "SELECT * FROM curiosities WHERE Curiosity LIKE '"."%".mysql_real_escape_string($Query)."%"."' $sort"; $result = mysql_query($query1) or die(mysql_error());
hmm, from the sounds of it the problem is lying in the sending of the data rather than the queries. Can you post the html for the form
<form id="Search" name="form1" method="post" action="searching.php"> <label> <span class="style3">Search By: </span> <select name="SearchBy" class="" id="select" style="width:120px;"> <option value="<?php echo $dropdownSearchByValue; ?>" selected="selected"><?php echo $dropdownSearchBy; ?></option> <option value="Category">Category</option> <option value="Date">Date</option> <option value="Keyword">Keyword</option> <option value="LastName">Last Name</option> <option value="Town">Town</option> <option value="ZipCode">Zip Code</option> </select> </label> <label> <span class="style3">Query:</span> <input name="SearchText" type="text" class="" id="textfield" value="<?php echo $Query; ?>" /> </label> <?php echo $Query; ?> <label><span class="style3">Sort By:</span> <?php $dropdownSortBy = "Most Recent"; $dropdownSortByValue = "MostRecent"; ?> <select name="SortBy" class="" id="select1" style="width:150px;"> <option value="<?php echo $dropdownSortByValue; ?>" selected="selected"><?php echo $dropdownSortBy; ?></option> <option value="LastName">Last Name</option> <option value="ZipCode">Zip Code</option> </select> </label> <label> <input type="hidden" value="<?php echo $dropdownSearchBy; ?>" name="dropdownSearchBy" /> <input type="hidden" value="<?php echo number_format($num_rows[0]); ?>" name="QueryNum" /> <input type="submit" name="button" id="button" value="Search" class="btn" /> </label> <label> <!--<input type="text" id="datepicker">--> </label> </form>
hmm, I don't see an input that you are getting the $_POST['Query'] from in that code whatsoever You should have an <input type="text" id="Query" name="Query" /> HTML: somewhere in there
$search = array(' '); $replace = array('%'); Change the above array to this $search = array(" "); $replace = array("%");
JAY this is he's query input: <input name="SearchText" type="text" class="" id="textfield" value="<?php echo $Query; ?>" /> timallard try to change this: //Takes spaces and adds wildcard $search = array(' '); $replace = array('%'); $subject = $SearchText; $SearchText = str_replace($search, $replace, $subject); to: //Takes spaces and adds wildcard $SearchText = $_POST['SearchText']; $SearchText = str_replace(" ", "%", $SearchText); and BTW.. for what do you use/need the $subject variable for?