发现占位符,并把再以阵列 [英] Finding placeholders and put then in an array

查看:129
本文介绍了发现占位符,并把再以阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的字符串我有占位,如:##消息##,##尾### Google分析##等

In my string I have place holders like: ##NEWSLETTER## , ##FOOTER# ##GOOGLEANALYTICS## etc.

那些占位符的每一个由分隔:##

Each of those placeholders is delimited by: ##

我要找到每个茨艾伦占位符,并把它们在数组中。

I want to find each of thos placeholders and put them in an array.

棘手的部分是,##分隔符中有什么可以是任何东西。

The tricky part is that what's inside the ## delimiters can be anything.

推荐答案

试试这个:

<?php

$s = "asdff ##HI## asdsad ##TEST## asdsadsadad";

preg_match_all("~##([^#]+)##~", $s, $result);

var_dump($result[1]);

打印:

array(2) {
  [0]=>
  string(2) "HI"
  [1]=>
  string(4) "TEST"
}

这篇关于发现占位符,并把再以阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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