• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

坑爹的正则,请教

php 搞代码 3年前 (2022-01-23) 23次浏览 已收录 0个评论
文章目录[隐藏]
config.php$_LANG['new_arrival']       = 'New Arrivals';$_LANG['hot_products']   = 'Hot Products';$_LANG['group_deals']     = 'Group Deals';$_LANG['specials']            = "Specials";$_LANG['after']            = '<div>Contact cu\'stomer</div> <table><tr><td>service for</td></tr> <tr><td>order status and</td></tr>  <tr><td>other after-sales issues</td></tr></table>'; $_LANG['group_deals']     = 'Group Deals'; $subject = file_get_contents("config.php");$pattern = '这里正则要如何写呢'; preg_match_all($pattern, $subject, $matches); print_r($matches);我要取出等号后面的所有内容,正则要怎样写呢? 请注意等号后面字符串中的符号(单引号,双引号,转义符己及换行都要取到)。结果如下:1. 'New Arrivals' 2. 'Hot Products' 3. 'Group Deals'4. "Specials"5.  '<div>Contact cu\'stomer</div> <table><tr><td>service for</td></tr> <tr><td>order status and</td></tr> <tr><td>other after-sales issues</td></tr></table>'

回复讨论(解决方案)

想不通,你那都是个数组了可以直接通过键名来取干嘛还用正则!还有你干嘛要通过file_get_contents来取config.php中的数据?你完全可以把那个数组返回然后直接通过数组来操作还方便些

$subject =<<< 'TXT'$_LANG['new_arrival']       = 'New Arrivals';$_LANG['hot_products']   = 'Hot Products';$_LANG['group_deals']     = 'Group Deals';$_LANG['specials']            = "Specials";$_LANG['after']            = '<div>Contact cu\'stomer</div> <table><tr><td>service for</td></tr> <tr><td>order status and</td></tr>  <tr><td>other after-sales issues</td></tr></table>'; $_LANG['group_deals']     = 'Group Deals';TXT;$pattern = '/.*=\s*(.+);/sU'; preg_match_all($pattern, $subject, $matches); print_r($matches[1]);

Arr

)本文来源gaodai.ma#com搞#代!码网_

搞代gaodaima码ay
(
[0] => ‘New Arrivals’
[1] => ‘Hot Products’
[2] => ‘Group Deals’
[3] => “Specials”
[4] => ‘

Contact cu\’stomer

service for
order status and
other after-sales issues


[5] => ‘Group Deals’
)

技术高手,CSDN还是蛮多的。

config.php 一般 include 进来读数组取值就行

=\s([”””A-Za-z1-9\s\/\\-]*)

=\s*([”””A-Za-z1-9\s\/\\-]*)

config.php 一般 include 进来读数组取值就行

嗯。数组是可以直接用。但不是我的问题所在哈。


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:坑爹的正则,请教

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址