怎么找到的话,它基于一个列表之后取消(删除)字符? [英] How find words and abolish (delete) characters after it based in a list?

查看:121
本文介绍了怎么找到的话,它基于一个列表之后取消(删除)字符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我想查PHP字符串中的存在,并且删除之后我可以使用的话:

If I want to check 'php' exist in a string and delete the words after it I could just use:

$string = 'hello world php is a bla bla..';
$string = explode(' php ', $string);
echo $string[0];

但是,如果我有多个字,而不是仅仅PHP?例如以下几首歌的名字有功勋,壮举,金融时报,英尺..这是他们四个人。

But what if I have multiple words instead of just 'php'? For example few song name below has 'feats','feat','ft','ft.'.. that's four of them.

我要让像新航 - 弹性壮举brunos火星变成只是SIA - 弹性。

I want to make like 'sia - elastic feat brunos mars' become just 'sia - elastic'.

推荐答案

这是你所需要的code:

This is the code that you need:

<?php

$string = 'sia - elastic feat brunos mars';

$array = array('feats', 'feat', 'ft', 'ft.');

for($i = 0; $i < count($array); $i++) {
  $out = explode(' ' . $array[$i] . ' ', $string);
  if (count($out) > 1) {
       break;
  }   
}

echo $out[0];

?>

这篇关于怎么找到的话,它基于一个列表之后取消(删除)字符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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