PHP 正则替换 "br />" 标签

本文介绍了一个使用PHP进行正则表达式替换的例子,将HTML中的<br/>标签替换为换行符 ,适用于文本处理和格式转换场景。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

正则替换 <br />,为  "\r\n"

$str =  "1234567<br />1234567<br />1234567";

echo preg_replace("/<br\s*\/?>/i","\r\n",$str);

 

<!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>前端网-登录注册</title> </head> <body> <h1>wasai</h1> <p id="p1">不错</p> <img src="1.jbg" alt="示例图片"> <table border="1"> <caption>用户信息表</caption> <tr> <th>序号</th> <th>姓名</th> <th>性别</th> <th>年龄</th> </tr> <tr> <td>1</td> <td>张三</td> <td>男</td> <td>18</td> </tr> <tr> <td>2</td> <td>王五</td> <td>男</td> <td>22</td> </tr> </table> <br> <a href="login.html">登录</a> <form action="login.php" method="post" onsubmit="return test()"> <script> function test() { const username = document.getElementById('username').value; const password = document.getElementById('password').value; alert(`用户名:${username}\n密码:${password}`); return false; // 阻止表单提交 } </script> <label>用户:<input type="text" id="username" name="username" required></label><br> <label>密码:<input type="password" id="password" name="password" required></label><br> 男:<input type="radio" name="sex" value="male" required> 女:<input type="radio" name="sex" value="female"><br> 打游戏:<input type="checkbox" name="hobby[]" value="gaming"> 听音乐:<input type="checkbox" name="hobby[]" value="music"> 看小说:<input type="checkbox" name="hobby[]" value="novel"><br> <select id="city" name="city"> <option value="chengdu">都</option> <option value="guangan">广安</option> <option value="beijing">北京</option> </select> <input type="file" name="file"> <textarea id="comment" name="comment" rows="5" cols="20"></textarea> <input type="submit" value="提交"> <button type="button">注册</button> </form> <script src="test.js"></script> </body> </html> 添加if来判断密码输入错误
最新发布
03-09
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值