note 84910 added to function.strpos
| From: | ChuzasoftInc dot ARGENTINA at osu1 dot php dot net | Date: | Tue, 05 Aug 2008 19:16:35 +0000 |
| Subject: | note 84910 added to function.strpos | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-143180@lists.php.net to get a copy of this message | ||
Hi! Don't you people miss the pretty comparison operator 'LIKE' from mySql in PHP??.
I've made this funtion to emulate that method. It's for search a match string into another
String
using the '%' caracter just like you do un the LIKE syntax.
For example:
<?php
$mystring = "Hi, this is good!";
$searchthis = "%thi% goo%";
$resp = milike($mystring,$searchthis);
if ($resp){
echo "milike = VERDADERO";
} else{
echo "milike = FALSO";
}
?>
Will print:
milike = VERDADERO
and so on...
this is the function:
<?php
function milike($cadena,$busca){
if($busca=="") return 1;
$vi = split("%",$busca);
$offset=0;
for($n=0;$n<count($vi);$n++){
if($vi[$n]== ""){
if($vi[0]== ""){
$tieneini = 1;
}
} else {
$newoff=strpos($cadena,$vi[$n],$offset);
if($newoff!==false){
if(!$tieneini){
if($offset!=$newoff){
return false;
}
}
if($n==count($vi)-1){
if($vi[$n] != substr($cadena,strlen($cadena)-strlen($vi[$n]), strlen($vi[$n]))){
return false;
}
} else {
$offset = $newoff + strlen($vi[$n]);
}
} else {
return false;
}
}
}
return true;
}
?>
Good luck!
----
Server IP: 208.69.120.35
Probable Submitter: 200.41.23.222
----
Manual Page -- http://www.php.net/manual/en/function.strpos.php
Edit -- https://master.php.net/note/edit/84910
Del: integrated -- https://master.php.net/note/delete/84910/integrated
Del: useless -- https://master.php.net/note/delete/84910/useless
Del: bad code -- https://master.php.net/note/delete/84910/bad+code
Del: spam -- https://master.php.net/note/delete/84910/spam
Del: non-english -- https://master.php.net/note/delete/84910/non-english
Del: in docs -- https://master.php.net/note/delete/84910/in+docs
Del: other reasons-- https://master.php.net/note/delete/84910
Reject -- https://master.php.net/note/reject/84910
Search -- https://master.php.net/manage/user-notes.php