地域のクリーンURLを取得しようとしていますが、$ _GET varialにクリーンURL機能が適用されている関連する地区に属しています。私は2つのページを持っています.1つ目はdistrict.phpで、この関数を使ってクリーンURLを生成する関連する地域にリンクしています。以下district.phpページのコードがある: - 同じ地域ページ
<?php
$remove[] = " ";
function clean($string) {
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
$string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
$string = preg_replace('/-+/', '-', $string); // Replaces multiple hyphens with single one.
return $string;
}
include($_SERVER['DOCUMENT_ROOT'].'/database-path.php');
$district = str_replace('-',' ',$_GET['district']);
$state = str_replace('-',' ',$_GET['state']);
$sql="SELECT * FROM table_name WHERE district='$district' AND state='$state'";
$result = mysqli_query($con,$sql);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$id = $row['id'];
$district = $row['district'];
$locality = $row['locality'];
$state = $row['state'];
$iso = $row['iso'];
}
?>
、コードは、関連地域のきれいなURLを生成するために使用される下記 -
<a href=\"/".str_replace($remove, "-", clean(strtolower($row['locality'])))."-".$row['id']."\">" . $row["locality"]. "</a>
上記のコードは、URLを生成しています地区ページの "locality-page-url-with-decoded-id-number"のやり方で、すべての地域ページに送信する。
RewriteRule ^([^/]*)-([^/]*)$ locality.php?locality=$1&id=$2 [L]
- :以下
は、私はきれいなURL<?php
function clean($string) {
$string = str_replace(' ', '-', $string); // Replaces all spaces with hyphens.
$string = preg_replace('/[^A-Za-z0-9\-]/', '', $string); // Removes special chars.
$string = preg_replace('/-+/', '-', $string); // Replaces multiple hyphens with single one.
return $string;
}
include($_SERVER['DOCUMENT_ROOT'].'/database-path.php');
$locality = clean($_GET['locality']);
$localID = base64_decode($_GET['id']) ;
$sql="SELECT * FROM table_name WHERE locality='$locality' AND id='$localID'";
$result = mysqli_query($con,$sql);
$rowcount=mysqli_num_rows($result);
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
$locality = $row['locality'];
$content = $row['content'];
$district = $row['district'];
$state = $row['state'];
$iso = $row['fld_iso'];
}
}
?>
htaccesコードを取得するために$ _GET変数に同じクリーンな関数を適用しようとしているlocality.phpのコードです今私が直面している問題は、$locality = clean($_GET['locality']);
がここでは動作していないということです。エラー404に戻っています。ローカリティの値がクリアされていません。フィールドで使用可能なすべての文字を使用して$ _GET変数からクリーン関数を削除した後に同じものを手動で試してみると、正常に動作します。ページのURLにローカリティのクリーンな値を持つ行の値を取得するためにIDを主変数として使用できる方法はありますか?
サンプルURLを提供して、動作させようとしていますか? – vnt
@vnt地区ページで生成されるURLの例: - http:// domainname.com/text-text-text-Mjk2 これは整頓されたURLです。 - http://domainname.com/text .-& - text-text-Mjk2' –
https://stackoverflow.com/questions/に「クリーン」機能が適用されています。 14114411/remove-all-special-characters-from-a-stringですが、現時点で評判スコアが低いため$ _GET変数にどのように適用するかを尋ねてこのページにコメントすることはできませんでした。 –