note 115032 added to function.preg-replace

From: Date: Thu, 15 May 2014 10:26:12 +0000
Subject: note 115032 added to function.preg-replace
Groups: php.notes 
Request: Send a blank email to php-notes+get-199541@lists.php.net to get a copy of this message
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> ---- Server IP: 80.64.47.13 Probable Submitter: 80.169.78.99 ---- Manual Page -- http://php.net/manual/en/function.preg-replace.php Edit -- https://master.php.net/note/edit/115032 Del: integrated -- https://master.php.net/note/delete/115032/integrated Del: useless -- https://master.php.net/note/delete/115032/useless Del: bad code -- https://master.php.net/note/delete/115032/bad+code Del: spam -- https://master.php.net/note/delete/115032/spam Del: non-english -- https://master.php.net/note/delete/115032/non-english Del: in docs -- https://master.php.net/note/delete/115032/in+docs Del: other reasons-- https://master.php.net/note/delete/115032 Reject -- https://master.php.net/note/reject/115032 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#199541) next »