Php 标记系统从一个数组到另一个数组的交叉引用

Php 标记系统从一个数组到另一个数组的交叉引用,php,arrays,multidimensional-array,preg-match,Php,Arrays,Multidimensional Array,Preg Match,我正在建立一个标签系统 我想让它检查一些文字。 然后检查文本是否包含数组中列出的任何术语。 如果没有,则输出另一个数组中列出的相应文本?(不确定是否应该这样做) 到目前为止 <?php $information = "This is the sentence that will be checked 123 hello world happy"; $check = array( 'hello','1','234','andy','happy', 'good mood'); $nam

我正在建立一个标签系统

我想让它检查一些文字。 然后检查文本是否包含数组中列出的任何术语。 如果没有,则输出另一个数组中列出的相应文本?(不确定是否应该这样做)

到目前为止

<?php
$information = "This is the sentence that will be checked 123 hello world happy";   

$check = array( 'hello','1','234','andy','happy', 'good mood');
$name = array ('bonjour','one','twothreefour','andrew','happy','happy');

foreach ($check as $value)

 if (preg_match("/".$value."/i",$information)) {
      $output = "<a href='/search/result/?q=".$value."'>".$name."</a>";
      print $output. " ";
  }
?>

它在语句中表示$name的位置是我希望它输出相应单词的位置。我这样做的原因是因为将有一个类似的短语,我想作为一个单一的输出一些变化

乙二醇

“快乐”、“高兴”、“好心情”都会输出为“快乐”

尝试以下方法:

$check = array( 'happy' => ".*(happy|good mood|cheerful).*" ) foreach ($check as $key => $value) { $matches = array(); if (preg_match('/'.$value.'/i',$information, &$matches)) { ... } } $check=数组( “快乐”=>“*(快乐、心情好、开朗)。” ) foreach($key=>$value){ $matches=array(); if(preg_match('/'.$value.'/i',$information,&$matches)){…} }
更改数组声明和循环,如下所示:

$check = array(
        'hello' => 'bonjour',
        '1' => 'one',
        '234' => 'twothreefour',
        'andy' => 'andrew',
        'happy' => 'happy',
        'good mood' => 'happy',
    );

foreach ($check as $value => $name)
代码的其余部分保持不变。我会选择不同的变量名,但这是所需的最小更改