note 115032 deleted from function.preg-replace by cmb

From: Date: Mon, 21 Nov 2016 19:41:16 +0000
Subject: note 115032 deleted from function.preg-replace by cmb
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-207311@lists.php.net to get a copy of this message
Note Submitter: dhgouveia at gmail dot com ---- if you want to replace only the content of specific div using the ID you can do this : <?php $id = "my-id"; $content = '<div id="my-id">Hello World</div><div id="other-id"> My World</div>'; $replacement = "Hello Planet"; $result = preg_replace('/(<div.*?id=\"'.$id.'\"[^>]*>)(.*?)(<\/div>)/i', "$1{$replacement}$3", $content); echo $result: ?> should print : <div id="my-id">Hello Planet</div><div id="other-id"> My World</div>

« previous php.notes (#207311) next »