remove_before ()

0 Cevap php

Is there some better way to do the below? (without having the possibility of a fatal error)

function remove_before($needle,$haystack){
    return substr(strstr($haystack,$needle),strlen($needle)); 
}

like strstr($haystack,$needle) but without the needle in the returned string, and I might as well ask if this can be improved too...

function remove_after($needle,$haystack){
    return substr($haystack, 0, strrpos($haystack, $needle));
}

Bu iğne sonra son oluşumu şeritler sonra dize kaldırmak ve iğne ilk geçtiği önce şeritler önce dize kaldırmak unutmayın.

edit: example:

$needle = '@@';
$haystack = 'one@@two@@three';
remove_after($needle,$haystack);//returns one@@two
remove_before($needle,$haystack)://returns two@@three

edit: I will leave it here for other people to reference.

0 Cevap