Jump to content

array key problem


aruncourage

Recommended Posts

<?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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.