منذ 3 ساعة مضت
(منذ 4 ساعة مضت )nnnjk كتب : السلام عليكم جميعاعليكم السلام
في الكود اعلاه ممكن طريقة طباعة عدد نتائج البحث بعد البحث عن الكلمة
PHP كود :
<?php
@header('Content-type: text/html;charset=windows-1256');
$results_per_page = 10; // عدد النتائج في كل صفحة
$current_page = isset($_GET['page']) ? (int)$_GET['page'] : 1;
if($_POST || isset($_GET['word'])){
$search = isset($_POST['word']) ? $_POST['word'] : $_GET['word'];
$lines = file('http://xxx.com/files/date.mfh');
if (strlen($search) < 3){
echo "كلمة البحث يجب أن تكون 3 أحرف على الأقل";
} else {
// جمع كل النتائج أولاً
$all_results = [];
foreach($lines as $line){
if(strpos($line, $search) !== false){
$all_results[] = $line;
}
}
// حساب عدد النتائج والصفحات
$total_results = count($all_results);
$total_pages = ceil($total_results / $results_per_page);
// طباعة عدد النتائج
echo "<p>عدد النتائج: <strong>$total_results</strong> نتيجة</p>";
// عرض نتائج الصفحة الحالية فقط
$start = ($current_page - 1) * $results_per_page;
$page_results = array_slice($all_results, $start, $results_per_page);
foreach($page_results as $line){
echo $line . "<br>";
}
// روابط الصفحات
if($total_pages > 1){
echo "<div style='margin-top:10px'>";
for($i = 1; $i <= $total_pages; $i++){
if($i == $current_page){
echo "<strong>[$i]</strong> ";
} else {
echo "<a href='?page=$i&word=" . urlencode($search) . "'>$i</a> ";
}
}
echo "</div>";
}
}
}
?>
<html>
<head>
<title>بحث في الملف</title>
</head>
<body>
<h3>بحث في الملف</h3>
<form action='' method='post'>
كلمة البحث: <input type='text' name='word' />
<input type='submit' value='بحث' />
</form>
</body>
</html>


![[صورة مرفقة: 177461173141861.gif]](https://up6.cc/2026/03/177461173141861.gif)