2016-09-30 14 views
-4

文字列をその変数に置き換えます。私はそれが文字列に( ')を受け入れるにはどうすればいいのか分かりますか?例えばPHP - 配列上の文字列を置換する

$string = ' *this* is 'a' test' '; 
$regexes = array('/~(.*?)~/six','/\*(.*?)\*/six'); 
$replaces = array('<i>$1</i>','<b>$1</b>'); 
$new_string = preg_replace($regexes, $replaces, $string); 

echo $new_string; 

を言わせて、私はそれが大胆イタリックテキストに変更することができますが、文字列は 『』「」している場合、それはエラーになります。どのようにこれを達成したいですか?

+0

http://parsedown.org/です! –

+1

'addslashes($ string)'を使用してください。 –

+0

あなたが意味するもの:preg_quote()私は推測します)) – Deep

答えて

1

これはあなたに役立つかもしれませんが、必要に応じてaddslashesstripslashesを使用してください。

<?php 
$string = " *this* is 'a' test' "; 
$string = addslashes($string); 
$regexes = array('/~(.*?)~/six','/\*(.*?)\*/six'); 
$replaces = array('<i>$1</i>','<b>$1</b>'); 
$new_string = preg_replace($regexes, $replaces, $string); 
echo stripslashes($new_string); 
?> 

この出力: - 車輪の再発明をしないでくださいこのは '' テスト」

+1

助けてくれてありがとう!できます – Amran

関連する問題