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

Popular posts from this blog

OpenCV OpenCL: Convert Mat to Bitmap in JNI Layer for Android -

android - org.xmlpull.v1.XmlPullParserException: expected: START_TAG {http://schemas.xmlsoap.org/soap/envelope/}Envelope -

python - How to remove the Xframe Options header in django? -