如何迭代循环内搜索字符串固定的关键字后的任何单词? [英] How to iterate loop inside a string searching for any word aftera fixed keyword?

查看:159
本文介绍了如何迭代循环内搜索字符串固定的关键字后的任何单词?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个像PHP的稻田,PHP的Pranav,PHP的部分,现在我有一个计数为3,现在我应该如何迭代循环在字符串瞄准字符串PHP后显示所有的名称?

好的这是字串 BEGIN IF(NEW.name!= OLD.name)然后插入到jos_menuaudit set menuid = OLD.id ,oldvalue = OLD.name,newvalue = NEW.name,field =name; END IF; IF(NEW.alias!= OLD.alias)THEN INSERT INTO jos_menuaudit set menuid = OLD.id,oldvalue = OLD.alias, newvalue = NEW.alias,field =alias; END IF; END 其中我搜索 IF(NEW。,并在此之后特殊的其他字符串不应该显示,因此无论何时在循环中,它发现 IF(NEW。我musr得到一个字旁边。并以这种方式一个数组应该准备好使用。

解决方案

使用 explode substr

  $ str =PHP Paddy,PHP Pranav,PHP Parth; 
$ ary = explode(',',$ str);
foreach($ ary as $ str){
echo substr($ str,4);
}


Suppose I have a sting as "PHP Paddy,PHP Pranav,PHP Parth", now i have a count as 3,now how should I iterate loop in the string aiming on string after "PHP " to display the all the names?

Alright This is the string "BEGIN IF (NEW.name != OLD.name) THEN INSERT INTO jos_menuaudit set menuid=OLD.id, oldvalue = OLD.name, newvalue = NEW.name, field = "name"; END IF; IF (NEW.alias != OLD.alias) THEN INSERT INTO jos_menuaudit set menuid=OLD.id, oldvalue = OLD.alias, newvalue = NEW.alias, field = "alias"; END IF; END" in which i am searching the particular word after " IF (NEW.", and after that particualar others strings should not b displayed, hence whenever in a loop it finds " IF (NEW." I musr get a word just next to it. and in this way an array should b ready for to use.

解决方案

Use explode and substr:

$str =  "PHP Paddy,PHP Pranav,PHP Parth";    
$ary = explode(',', $str);
foreach($ary as $str){
   echo substr($str, 4);
}

这篇关于如何迭代循环内搜索字符串固定的关键字后的任何单词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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