PDA

View Full Version : خطای مهلک در



ms11309
شنبه 21 تیر 1393, 18:28 عصر
سلام دوستان
یه خطا در کد زیر دریافت میکنم که دلیلش رو نمیدونم
لطفا راهنمایی کنید مشکلش کجاست؟



Fatal error: Cannot redeclare before() (previously declared in /home/***/public_html/on.php:3) in /home/***/public_html/on.php on line 5




<?php
ini_set("display_errors", 0);
function before($this, $inthat) {
return substr($inthat, 0, strpos($inthat, $this));
}
function after($this, $inthat) {
if(!is_bool(strpos($inthat, $this))) {
return substr($inthat, strpos($inthat,$this)+strlen($this));
} else {
return false;
}
}
function between($this, $that, $inthat) {
return before($that, after($this, $inthat));
}
function occurrencecount($this, $that, $inthat, $count) {
$newinthat = after("$that", after("$this", $inthat));
if($newinthat != false) {
$count = $count + 1;
return occurrencecount($this, $that, $newinthat, $count);
} else {
return $count;
}
}
?>


لازم به ذکر کل کد اینصفحه همینه

لطفا هرچه سریعتر کمکم کنید خواهشااااا

H:Shojaei
شنبه 21 تیر 1393, 18:58 عصر
سلام...
این خطا داره میگه نمیتونید تابع before رو دوباره بسازید چون قبلا تعریف شده واسه فهمیدن این که قبلا تعریف شده یا نه از تابع function_exist میتونید استفاده کنید:


if (!function_exists('before')) {
// ... proceed to declare your function
}

ms11309
شنبه 21 تیر 1393, 19:12 عصر
سلام...
این خطا داره میگه نمیتونید تابع before رو دوباره بسازید چون قبلا تعریف شده واسه فهمیدن این که قبلا تعریف شده یا نه از تابع function_exist میتونید استفاده کنید:


if (!function_exists('before')) {
// ... proceed to declare your function
}

تشکر از پاسختون
این تابع رو کجا و چطور استفاده کنم؟

ms11309
شنبه 21 تیر 1393, 19:14 عصر
<?php
ini_set("display_errors", 0);
if (!function_exists('before')) {
function before($this, $inthat) {
return substr($inthat, 0, strpos($inthat, $this));
}
function after($this, $inthat) {
if(!is_bool(strpos($inthat, $this))) {
return substr($inthat, strpos($inthat,$this)+strlen($this));
} else {
return false;
}
}
function between($this, $that, $inthat) {
return before($that, after($this, $inthat));
}
function occurrencecount($this, $that, $inthat, $count) {
$newinthat = after("$that", after("$this", $inthat));
if($newinthat != false) {
$count = $count + 1;
return occurrencecount($this, $that, $newinthat, $count);
} else {
return $count;
}
}
}
?>



به این شکل درسته؟

ms11309
شنبه 21 تیر 1393, 19:24 عصر
به نظر درست شد
متشکر از جناب H:Shojaei (http://barnamenevis.org/member.php?241637-H-Shojaei)

یه مشکل دیگه ای هم دارم
تابع منسوخ شده eregi

با هر تابعی جایگزین میکنم باز هم مشکل داره و در لاگ ارور میده



elseif(!eregi('^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $email)){
echo'<br><div align="center"><font color="#FF0000" face="Tahoma">درست وارد كنيد</font></div><br>';


باید چیکار کرد اینو؟

H:Shojaei
شنبه 21 تیر 1393, 20:25 عصر
تابع preg_match جای این تابع باید استفاده کنید...

Tarragon
شنبه 21 تیر 1393, 20:52 عصر
در ضمن برای چک کردن ایمیل بهتره که از تابع Filter_var استفاده کنید.

ms11309
جمعه 27 تیر 1393, 17:49 عصر
در ضمن برای چک کردن ایمیل بهتره که از تابع Filter_var استفاده کنید. preg_match درست کار نمیکنه یعنی انگار اصلا نیست نحوه استفاده این Filter_var چطوریه؟

hamedarian2009
جمعه 27 تیر 1393, 18:28 عصر
preg_match درست کار نمیکنه یعنی انگار اصلا نیست نحوه استفاده این Filter_var چطوریه؟

http://ir2.php.net/manual/en/function.filter-var.php



if(!filter_var('bob@example.com', FILTER_VALIDATE_EMAIL)){
echo 'Incorrect email format.';
}