前提・実現したいこと
HTMLを簡単に書けるものを作っているのですが、正規表現で困っています。
.#bold(文字)とすると、「文字」となり、#strike(文字)とすれば「文字」となるものです。
想像していたのは「文字」です。
発生している問題・エラーメッセージ
.#bold(#strike(aa))とすると#bold(aa)となってしまいます。
該当のソースコード
php
1$html = $_POST['data']; 2$html = preg_replace("/\#bold((((?>[^()]+)|(?R))*))/x",'<font style="font-weight: bold;">${1}</font>',$html); 3$html = preg_replace("/\#strike((((?>[^()]+)|(?R))*))/x",'<font style="text-decoration: line-through;">${1}</font>',$html); 4echo $html;
html
1<form name="frm" method="post" action="/converter"> 2 <input type="submit" value="プレビュー" /><br> 3 <textarea rows="15" name="data" style="width: 50%;display: inline-block;"></textarea> 4</form>
補足情報
PHP 7.1.15
Apache/2.4.6 (CentOS)
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。