Jump to content
FiliBlox

Problema javascript

Recommended Posts

Posted

salut , stie cineva de ce cand caut pe site un cuvant cu ' nu imi cauta ? de exemplu: i'm angel ... in site am search.php

<?php
$cautare=$_POST['search'];
$cautare = iconv('iso-8859-1', 'US-ASCII//TRANSLIT', $cautare);
$ip=$_SERVER['REMOTE_ADDR'];
include('config.php');
include('functions.php');
$con=mysql_connect($server,$user,$pass);
if (!$con)
{
die('Cannot connect to mysql ' . mysql_error());
}
$ip=$_SERVER['REMOTE_ADDR'];
mysql_select_db($db, $con);
$query="SELECT * FROM tags where cautare='$cautare'";
$res=mysql_query($query) or die(mysql_error());
if (mysql_num_rows($res)==0 && strlen($cautare)>=3)
{
$q="INSERT INTO tags (cautare, ip) VALUES('$cautare','$ip')";
mysql_query($q) or die(mysql_error());
}
mysql_close();

$cautare=str_replace(" ","-",$cautare);
$cautare=str_replace("'","",$cautare);
$cautare=str_replace("`","",$cautare);
$cautare=str_replace("[","",$cautare);
$cautare=str_replace("_","-",$cautare);
$cautare=str_replace("]","",$cautare);
$cautare=str_replace("(","",$cautare);
$cautare=str_replace(")","",$cautare);
$cautare=str_replace(",","",$cautare);
$cautare=str_replace("."," ",$cautare);
$cautare=str_replace(":","",$cautare);
$cautare=str_replace(";","",$cautare);
$cautare=str_replace("?","",$cautare);
$cautare=str_replace("!","",$cautare);
$cautare=str_replace("&"," ",$cautare);
$cautare=str_replace("@","",$cautare);
$cautare=str_replace("*","",$cautare);
$cautare=str_replace("^","",$cautare);
$cautare=str_replace("%","",$cautare);
$cautare=str_replace("#","",$cautare);
$cautare=str_replace("=","",$cautare);
$cautare=str_replace("+","",$cautare);
$cautare=str_replace("<","",$cautare);
$cautare=str_replace(">","",$cautare);
$cautare=str_replace("|","",$cautare);
$cautare=str_replace("{","",$cautare);
$cautare=str_replace("}","",$cautare);
$cautare=str_replace("'\'","",$cautare);
$cautare=str_replace("/"," ",$cautare);
$cautare=str_replace("~","",$cautare);
$cautare=str_replace(" "," ",$cautare);
$cautare=str_replace(" "," ",$cautare);
$cautare=str_replace(" "," ",$cautare);
$cautare=str_replace(" ","-",$cautare);
mysql_close($con);
header("Location: http://www.site.net/download/" . htmlspecialchars($cautare) . "/");
?>

si daca bag in script un javascript e totul oki imi cauta si cand scriu : i'm angel si etc , dar nu imi baga in baza de date in tags ce se cauta pe site .

function CreateBookmarkLink() {
var title = 'site.net : Sursa Ta De Muzica Noua';
var url = 'http://www.site.net/';

if (window.sidebar) { // Mozilla Firefox Bookmark
window.sidebar.addPanel(title, url,"");
} else if( window.external ) { // IE Favorite
window.external.AddFavorite( url, title); }
else if(window.opera && window.print) { // Opera Hotlist
return true; }
}

if (top.location != self.location) {
top.location = self.location.href
}

$("#search-btn").click(function() {

$(".error").hide();
var hasError = false;
var searchReg = /^[a-zA-Z0-9-]+$/;
var searchVal = $("#search-text").val();

//alert(searchVal);

if(searchVal == '') {
$("#search-text").after('<span class="error" style="color: #F11111;">Nu ai introdus nimic in campul de cautare</span>');
hasError = true;
} else if(searchVal.length < 4) {
$("#search-text").after('<span class="error" style="color: #F11111;">Text prea scurt, minim 4 caractere</span>');
hasError = true;
}/*else if(!searchReg.test(searchVal)) {
$("#search-text").after('<span class="error" style="color: #F11111;">Enter valid text.</span>');
hasError = true;
}*/
if(hasError == true) {return false;}

searchVal = perma(searchVal.removeDiacritics());

window.location = 'http://www.site.net/download/'+searchVal+'/';

return false;
});

function perma(value) {
value = value.replace(new RegExp("([^a-zA-Z0-9-]{1,})", "g"), "-");
value = value.replace(" ",'-');
value = value.replace("_",'-');
value = value.replace("a",'a');
value = value.replace("î",'i');
value = value.replace("Î",'i');
value = value.replace("í",'i');
value = value.replace("â",'a');
value = value.replace("á",'a');
value = value.replace("s",'s');
value = value.replace("t",'t');
value = value.replace("ú",'u');
value = value.replace("",'-');
value = value.replace("é",'e');
value = value.replace("–",'-');
value = value.replace("“",'-');
value = value.replace("ç",'c');
value = value.replace("ë",'e');
value = value.replace("ä",'a');
value = value.replace("Ö",'o');
value = value.replace("ö",'o');
value = value.replace("ó",'o');
value = value.replace("ü",'u');
value = value.replace("’",'-');
value = value.replace("´",'-');
value = value.replace("µ",'-');
value = value.replace("°",'-');
value = value.replace("—",'-');
value = value.replace("ß",'-');
value = value.replace("š",'s');
value = value.replace("€",'-');
value = value.replace("„",'-');
value = value.replace("§",'-');
value = value.replace("Ç",'c');
value = value.replace("'",'-');
value = value.replace("‘",'-');
value = value.replace("¨",'-');
value = value.replace("Š",'s');
value = value.replace("ñ",'n');
value = value.replace("è",'e');
value = value.replace("ò",'o');
value = value.replace("à",'a');
value = value.replace("ù",'u');
value = value.replace("[",'');
value = value.replace("]",'');
value = value.replace("(",'');
value = value.replace(")",'');
value = value.replace("*",'');
value = value.replace("*",'');
value = value.replace("|",'');
value = value.replace("!",'');
value = value.replace("£",'');
value = value.replace("$",'');
value = value.replace("%",'');
value = value.replace("/",'');
value = value.replace("^",'');
value = value.replace("?",'');
value = value.replace("+",'');
value = value.replace("@",'');
value = value.replace(".",'');
value = value.replace(",",'');
value = value.replace(";",'');
value = value.replace(":",'');
value = value.replace("<",'');
value = value.replace(">",'');

return value = value.replace(new RegExp("[_]{2,}", "g"), "-");
}

String.prototype.removeDiacritics = function() {
var diacritics = [
[/[\300-\306]/g, 'A'],
[/[\340-\346]/g, 'a'],
[/[\310-\313]/g, 'E'],
[/[\350-\353]/g, 'e'],
[/[\314-\317]/g, 'I'],
[/[\354-\357]/g, 'i'],
[/[\322-\330]/g, 'O'],
[/[\362-\370]/g, 'o'],
[/[\331-\334]/g, 'U'],
[/[\371-\374]/g, 'u'],
[/[\321]/g, 'N'],
[/[\361]/g, 'n'],
[/[\307]/g, 'C'],
[/[\347]/g, 'c'],
];
var s = this;
for (var i = 0; i < diacritics.length; i++) {
s = s.replace(diacritics[i][0], diacritics[i][1]);
}
return s;
}

function validate(frm)
{
if(frm.elements["search"].value.length<=2)
{
alert("Introduceti minim 3 caractere pentru cautare!");
return false;
}
return true;
}

Posted

In php ai $cautare=str_replace("'","",$cautare);

adica iti inlocuieste ' cu nimic

In javascript ai value = value.replace("’",'-');

adica iti inlocuieste ' cu -

In momentul cand cauti i'm an angel cu scriptul php, de fapt, o sa iti caute im an angel, ceea ce bineinteles, nu gaseste.

Incearca sa dai si in php "-" sau "'" in loc de ""

Posted

deci in search.php functia aia nu are nici o valoare oricum as modificao $cautare=str_replace("'","+ - spatiu . etc",$cautare);

cand introduc si javascriptu in site imi cauta bine dar nu imi introduce cautarea in baza de date in tags , ar mai trebui adaugat ceva in js cred sa posteze in baza de date , ca fara js in script posteaza in baza de date ce se cauta pe site ..

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.   Paste as plain text instead

  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...