The following html string is provided for intercepting the specified PHP string:
Aaaa
Bbbb
Cccc
Dddd
To output the following content:
Aaaa
Dddd
Delete the two
Previous content and
The simple code is also output as html, and the array method is not required.
Reply to discussion (solution)
$s = 'aaaa
bbbb
cccc
dddd
';echo preg_replace('/
\w+/', '', $s, 2);
aaaa
dddd
There is also a small problem. it is okay to run it separately, but when the above expression actually uses my string, because the second section of the br contains (), and the last section of the br contains "-", it is a problem to extract it.
$ S ='Aaaa
11 (22)
Cccc
Dd-dd
';
The screenshot is changed:
$ S ='Aaaa (22)
Cccc-dd
';
$s = 'aaaa
11(22)
cccc
dd-dd
';echo preg_replace('/
[\(\)-\w]+/', '', $s, 2);
Note: aaaa and cccc are Chinese characters.
Note: aaaa and cccc are Chinese characters.
$ S ='Chinese
11 (22)
Pinyin
Dd-dd
'; Echo preg_replace ('/
[\ X {4e00}-\ x {9fa5} \ w \ (\)-] +/U', '', $ s, 2); // UTF-8 encoding
Thank you. The first part of the screenshot is still misplaced. paste my original characters directly:
Computer programming
1-9 (1, 2)
Wang
3-307
To output two effects:
1.Computer programming
3-307
2.Computer programming
1-9
3-307
The second paragraph only removes the brackets and content.
1
echo preg_replace('/
[^<]+/', '', $s, 2);
2
echo preg_replace('/\(.+?\)/', '', $s);
1
echo preg_replace('/
[^<]+/', '', $s, 2);
2
echo preg_replace('/\(.+?\)/', '', $s);
Thank you, moderator. The first article is correct, and the second article "wang"
Still.
Echo preg_replace ('/
[\ X {4e00}-\ x {9fa5} \ w \ (\) \-,] +/U', '', $ s, 2); // UTF-8 encoding
You have more. add a comma in square brackets.
aaaa
bbbb
cccc
dddd
';$arr = explode('
', $str);array_splice($arr, 1, 2);echo implode('
', $arr);?>
Please help jordan102. The second echo preg_replace ('/\ (. +? \)/', '', $ S) also needs to cut off" Wang
.
echo preg_replace_callback('/
[^<]+/', 'foo', $s, 2); function foo($m){ return strpos($m[0], '(') !== false ? preg_replace('/\(.+?\)/','',$m[0]) : ''; }
Thank you. it is okay to run the statement separately. However, some of the preceding statements and spaces may cause problems.