我爱占星网 我爱占星网
首页
编程
java
php
前端
首页 编程 java php 前端

如何在文本中获取占位符?

I have a variable with a small text like:

$s = "bla bla bla {name} bla bla bla bla bla bla {city} bla bla bla {address}";

I need to use a regular expression to get ALL the name inside { }

In this case I need an array as result with:

  • "name"
  • "city"
  • "address"

How to use preg_match to get all the texts inside the brackets ?

Thanks

This works for me:

$s = "bla bla bla {name} bla bla bla bla bla bla {city} bla bla bla {address}";
preg_match_all("/\{([^\}]+)\}/i", $s, $matches);
$results = $matches[1];

近期文章

  • 命名约定或目录结构
  • php mysql查询没有正确执行
  • 将对象添加到数组 - assign_to_dorm函数
  • Wordpress:来自表单操作文件的MySQL查询
  • Simpletest正在运行我的所有测试两次。 为什么?
  • PHP基本会话用法
  • 如何获得与用户相关的类别明智的价值?
  • 插入查询 - 存储时间
  • 分为零,php
  • PHP / MySQL根据以前的if语句输出指定的字段
  • Facebook FQL。 哪个是按日期/时间排序的单个查询中获取所有页面更改的最简单方法?
  • Mysql - 进入列
  • 连接表MySQL时的未知列
  • 来自php脚本的MySQL数据库连接错误通过bash脚本运行
  • 404使用https与php脚本时出错
  • Webmin自动备份清理
  • 从Zend中的控制器中的视图传递数据
  • 多个php if($ category-> getId()==
  • CakePHP不显示右表中的数据
  • PHP Doctrine使用鉴别器映射查询继承的类

Copyright ©2022 我爱占星 All Rights Reserved.

浙ICP备2022030071号-1

部分图文来自网络,如有侵犯您的版权,请告诉我们删除

友情链接:代码精华