aruncourage Posted April 24, 2010 Share Posted April 24, 2010 <?php class Strmatch { public $a,$b,$c; function str($a,$b,$c) { $this->position($a,$c); } function position($tv,$ts) { $fvalue=substr($tv,0,1); $leng=strlen($ts); for($i=0;$i<$leng;$i++) { if($ts[$i]==$fvalue) { $count[$i]=$ts[$i]; } } $key=($count); $keyvalue=(array_keys($key)); $count=count($keyvalue); $lengtv=strlen($tv); for($i=0;$i<$count;$i++) { $str[$i]=substr($ts,$keyvalue[$i],$lengtv); $a1=$str; $a2[]=$tv; if(array_intersect($a1,$a2)) { $key=$keyvalue; echo $key; } } } } $test=new Strmatch(); $test->str('check','test','The check is completed'); ?> I wants fetch the appropriate key or matching key value in that function...how is done ? Please help me I trying to solve this problem from last 30hous ............Please help me........Thank you Link to comment https://forums.phpfreaks.com/topic/199567-array-key-problem/ Share on other sites More sharing options...
andrewgauger Posted April 24, 2010 Share Posted April 24, 2010 I hardly see any logic in this, so I hope you can clarify this: you execute the function str() passing three variables, the first of which you are attempting to match against the third? It looks like you are trying to see if the first argument is in the third? if this is what you want, then just execute echo strstr($c,$a); inplace of position() If you want to find out what position it occurs at subsitute echo strpos($c,$a); either way, review: http://www.php.net/manual/en/ref.strings.php Link to comment https://forums.phpfreaks.com/topic/199567-array-key-problem/#findComment-1047511 Share on other sites More sharing options...
aruncourage Posted April 24, 2010 Author Share Posted April 24, 2010 I would like to create the custom str_replace () function in php.so I have pass the 3 arguments ('replace'"targetvalue",'targetstring')...I think that I fall the logic . Please help me....... Link to comment https://forums.phpfreaks.com/topic/199567-array-key-problem/#findComment-1047513 Share on other sites More sharing options...
andrewgauger Posted April 24, 2010 Share Posted April 24, 2010 I can hardly see a reason to rewrite the function. http://php.net/manual/en/function.str-replace.php this one executes at a lower level than php does, so there is no way to optimize it without rewriting it in C. Can you explain one benefit of rewriting it (or are you doing this for educational reasons?) I don't mean to come off as condescending, I just don't understand why rewrite such a well written function. Link to comment https://forums.phpfreaks.com/topic/199567-array-key-problem/#findComment-1047514 Share on other sites More sharing options...
aruncourage Posted April 24, 2010 Author Share Posted April 24, 2010 It's for education purpose .......... i wants another help from you. i wants set the Password length in my register page .. how is made in php ? please help me. Thank you Link to comment https://forums.phpfreaks.com/topic/199567-array-key-problem/#findComment-1047516 Share on other sites More sharing options...
andrewgauger Posted April 24, 2010 Share Posted April 24, 2010 validating password length should be as easy as: $pass=$_POST['password']; if (strlen($pass) < 4){ echo "Password too short!"; } And I had an idea about rewriting str_replace: function str_replace_slow($haystack, $needle, $replace){ $array_temp=explode($needle, $haystack); return implode($replace, $array_temp); } Link to comment https://forums.phpfreaks.com/topic/199567-array-key-problem/#findComment-1047780 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.