php - Regex to replace tags content -
i have problem code:
$message='<ha>hello</ha>'; $message = str_replace('<ha>(.*?)</ha>', '<ha>bye</ha>', $message); echo $message;
the output still hello although want bye..it might simple using regex first time. in advance
use preg_replace
function:
$message='<ha>hello</ha>'; $message = preg_replace('/<ha>(.*?)<\/ha>/', '<ha>bye</ha>', $message); echo $message; // gives: <ha>bye</ha>
demo:
http://sandbox.onlinephpfunctions.com/code/9b0a2239a891223472e93f8a362e5946e5719df0
Comments
Post a Comment