这就是我所拥有的:
$search=htmlspecialchars($_GET['load']);
$say=mysql_query("SELECT * FROM madvideo WHERE MATCH (baslik) AGAINST ('*$search*' IN BOOLEAN MODE)");
$saydim=mysql_num_rows($say);
$count = $saydim;
$page = !empty($_GET["page"]) ? intval($_GET["page"]) : 1;
$s = ($page-1)*$perpage;
$sayfasayisi=ceil($count/$perpage);
if(ayaral("Arananlar-Kaydet")=="1") {
$ekle=cevir($search);
@mysql_query("insert into tag (baslik,tr,tarih) values ('$search','$ekle',now()) "); }
变量“$ search”将调用搜索词,我不知道我必须使用的条带语法去除那个令人讨厌的/////////字符。
编辑:创建单词的代码是:
$vtitle = str_replace("\r\n\r\n", ' ', $vtitle);
$words = explode(' ', $vtitle);
$k = count($words);
$k3 = ceil($k/3);
$new = array();
for ($i=0; $i<$k; $i+=$k3) {
$new[] = join(' ', array_slice($words,$i, $k3));
}
$tag1 = $new[0];
$tag2 = $new[1];
$tag3 = $new[2];
答案 0 :(得分:1)
编辑:
真实的例子......
<?php
if(isset($_REQUEST['str'])) {
$search = $_REQUEST['str'];
$ser_chk = strpos($search, "/");
if ($ser_chk > -1) {
$search = str_replace("/", "", $search);
}
}
?>
<h1><?php print $search; ?></h1>
<form action="" method="post">
<input type="text" size="100" value="search keywords////////////////////////////////////////////////" name="str" />
<input type="submit" />
</form>
链接测试:http://simplestudio.rs/tsto.php
至少做:
$search = mysql_real_escape_string($search);
此外,您可以检查这些字符,如果成立,只需用空字符串替换它们。
$ser_chk = strpos($search, "/");
if ($ser_chk > -1) {
$search = str_replace("/", "", $search);
}
答案 1 :(得分:1)
使用MySQL TRIM函数从字符串末尾删除,如下所示:
TRIM(TRAILING '/' FROM <string>)
@mysql_query("insert into tag (baslik,tr,tarih)
values (TRIM(TRAILING '/' FROM '$search'),'$ekle',now())")
要从开头和结尾剪裁,请使用以下
TRIM(BOTH '/' FROM <string>)
@mysql_query("insert into tag (baslik,tr,tarih)
values (TRIM(BOTH '/' FROM '$search'),'$ekle',now())")
要删除字符串的所有出现,请使用REPLACE函数,如下所示:
REPLACE(<string>, '/', '')
@mysql_query("insert into tag (baslik,tr,tarih)
values (REPLACE('$search', '/',''),'$ekle',now())")
希望它有所帮助...
答案 2 :(得分:1)
如果/
字符始终显示在$search
的末尾,则可以使用rtrim
使用第二个(可选)参数:
$search = "search keywords////////////////////////////////////////////////";
$search = rtrim($search, '/ ');
echo $search; // prints 'search keywords'
答案 3 :(得分:0)
$regex = "/\//";
$string = "////search";
$string = preg_replace($regex, '', $string);
echo $string;
答案 4 :(得分:0)
字符重复的灵活解决方案将是一个正则表达式。
$output = preg_replace('/\/[\/]+/', '/'. $input);
它将处理任意数量的“/”并将其替换为单个“/".