寻找一系列char的最快方法? [英] Fastest way to look for an array of char?

查看:52
本文介绍了寻找一系列char的最快方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




如果我有一个字符串,(变量len),我正在寻找阵列中第一个位置

的一个字符串从位置''''


例如,


//''haystack''

$ string =" PHP非常好,php还可以;

//针头

$ char [] =''P'';

$ char [] =''r'';

$ char [] =''k'';


我会搜索$从3开始的第一个$ char的字符串,它将是

返回7,(对于''g'')。


我可以使用很多strpos( ...)但这听起来效率不高。

那么获得第一名的最快方法是什么?


而且,我正在使用PHP 4.x,而不是5,(否则我想我会使用strpos(...))。


非常感谢提前。


Simon

Hi,

If I have a string, (variable len), and I am looking for the first position
of one char in array starting from position ''x''

For example,

// the ''haystack''
$string = "PHP is great, php is ok";
// the needles
$char[] = ''P'';
$char[] = ''r'';
$char[] = ''k'';

I would search the $string for the first $char starting from 3 and it would
return 7, (for ''g'').

I could use many strpos(...) but that does not sound very efficient.
So what would be the fastest way to get the first position?

And, I am using PHP 4.x, not 5, (otherwise I guess I would use strpos(...)).

Many thanks in advance.

Simon

推荐答案

string =" PHP很棒,php还可以;;

//针头
string = "PHP is great, php is ok";
// the needles


char [] =''P'';
char[] = ''P'';

char [] =''r'';
char[] = ''r'';


这篇关于寻找一系列char的最快方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆