dotcraq3249 2013-06-04 19:30
浏览 21
已采纳

如何使用PHP获取由哈希标记包围的匹配单词

I have something similar to this:

<a href="#action_link#" target="_blank">Token1</a><br>
<a href="##action_link##" target="_blank">Token1</a><br>

And I need to get only the one(s) that is/are surrounded by only one hashtag (#), for this sample I need only the first anchor tag.

I have tried also with grabbing the href attr to filter and make the regexp more easier with something like this:

preg_match_all('/<a\s[^>]*href=(\"??|\'??)(#action_link#?)[^>]*>/siU', $someHTML, $match);

But with no success :(

Could you please help me?

  • 写回答

1条回答 默认 最新

  • dqajyxqem115006813 2013-06-04 19:36
    关注

    You can use:

    preg_match('/\"\#(.*)\#\"/im', $string, $matches);
    print_r($matches);
    

    Where $string is your string to search

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于#flink#的问题:关于docker部署flink集成hadoop的yarn,请教个问题flink启动yarn-session.sh连不上hadoop
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 lammps拉伸应力应变曲线分析
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题