获取 php 中特定值之后的所有字符串

Get all string after specific value in php

我需要所需的输出,无论是 preg_match 还是爆炸,这都不是问题。我需要给定数组格式的输出。

我正在尝试从这个变量中拆分字符串

输入

嗨FF_nm, 您所在的城市是 FF_city,您的性别是 FF_gender。网络研讨会标题是 FF_extraparam1 你的名字又是 FF_nickname

输出

array => [nickname,city,gender,extraparam1,nickname]

代码

<?php
    $data = "Hi FF_nm,
Your city is  FF_city and your gender is FF_gender. webinar title is FF_extraparam1
Again your name is FF_nickname";

    if (($pos = strpos($data, "FIELDMERGE_")) !== FALSE) { 
        $whatIWant = substr($data, $pos+1); 
    }

    echo $whatIWant; 

    ?>

您可以将 explodeforeach 循环一起使用:

$arr = explode("FIELDMERGE_", $data);
array_shift($arr); // you don't need the first element
foreach($arr as $e) {
    $word = array_shift(explode(" ", $e)); //take the first word
    $res[] = preg_replace('/[^a-z\d]/i', '', $word); //remove the , / . / \n and so on...
}

参考:array-shift, explode, preg-replace

实例:https://3v4l.org/Oa1sn

您可以将 preg_match_all 与正后视模式一起使用。

preg_match_all('/(?<=FF_)\w+/', $data, $fields);
$output = $fields[0];