PDA

View Full Version : چگونه میشه یک کلمه مورد نظر را از جمله برداشت ؟ (حل شد)



reza-alborz
شنبه 27 مهر 1392, 07:46 صبح
با عرض سلام و خسته نباشید خدمت تمامی دوستان برنامه نویس

چگونه میتونم کلمه site رو از این جمله استخراج کنم؟

http://site.ir/fa/mainPage/

tmwebseo
شنبه 27 مهر 1392, 09:50 صبح
به مثال زیر نگاه کن


$mystring = 'abc';
$findme = 'a';
$pos = strpos($mystring, $findme);

// Note our use of ===. Simply == would not work as expected
// because the position of 'a' was the 0th (first) character.
if ($pos === false) {
echo "The string '$findme' was not found in the string '$mystring'";
} else {
echo "The string '$findme' was found in the string '$mystring'";
echo " and exists at position $pos";
}

reza-alborz
شنبه 27 مهر 1392, 10:46 صبح
تشکر
البته خودم با یک روش دیگه ای درست کردم


$url_array = preg_split("/\./", $url);
$url_name = substr($url_array[0], 7);