我有以下代码,它是存储在变量中的电子邮件消息的摘录:
$string = '<td colspan=3D"2"><span style=3D"display: none;">CORRES PONDANCE_ID:4</= span> <span style=3D"display: none;">CONFIRMATION_NUMBER:9986337900</s= pan></td><td colspan=3D"2"><span style=3D"display: none;">CORRESPO NDANCE_ID:4</= span> <span style=3D"display: none;">CONFIRMATION_NUMBER:9986337900</s= pan></td>'; preg_match('/CORRESPONDANCE_ID:([0-9]+)/', $string, $id_matches); print_r($id_matches);如果有一个换行符拆分正在搜索的字符串中的模式,我无法找到匹配CORRESPONDANCE_ID或子模式中的数字的方法。
我尝试在模式的末尾使用x和s修饰符,但无济于事。
任何人都可以帮我完成这个吗? 谢谢!!
I have the following code which is an extract from a an email message stored in a variable:
$string = '<td colspan=3D"2"><span style=3D"display: none;">CORRES PONDANCE_ID:4</= span> <span style=3D"display: none;">CONFIRMATION_NUMBER:9986337900</s= pan></td><td colspan=3D"2"><span style=3D"display: none;">CORRESPO NDANCE_ID:4</= span> <span style=3D"display: none;">CONFIRMATION_NUMBER:9986337900</s= pan></td>'; preg_match('/CORRESPONDANCE_ID:([0-9]+)/', $string, $id_matches); print_r($id_matches);I can't figure out a way to match CORRESPONDANCE_ID or the number in the subpattern if there is a newline that splits the pattern in the string that is being searched.
I have tried using the x and s modifiers at the end of the pattern but to no avail.
Can anyone please help me accomplish this? Thank you!!
最满意答案
您必须使用替换换行符等字符
preg_match_all('/CORRESPONDANCE_ID:([0-9]+)/', preg_replace('/\r?\n/', "", $string), $id_matches);或者将这些字符添加到正则表达式模式:
preg_match_all('/[A-Z\r\n]+_ID:([0-9]+)/', $string, $id_matches);在这两种情况下, $string变量都没有被修改。
You must use replacement for newlines characters such as
preg_match_all('/CORRESPONDANCE_ID:([0-9]+)/', preg_replace('/\r?\n/', "", $string), $id_matches);or add these characters to regex pattern:
preg_match_all('/[A-Z\r\n]+_ID:([0-9]+)/', $string, $id_matches);In both cases you $string variable does NOT been modified.
更多推荐
发布评论