[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 703
  • Last Modified:

PHP and REGEX: replace content in a div

In the previous question (http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_24344850.html#a24204541) I wanted to know how to replace everything in the <head>. This is working perfectly.

Now I need to find the below and replace it in my html:

<div id="news_archive_head_title">Directory</div>

I tried using the example but it seems to be going further than the next div (it's replace more code). Thanks.
0
level9wizard
Asked:
level9wizard
2 Solutions
 
mostartCommented:
don't you think it would be a lot more easy to actually store the different content in variables and replace them under certain conditions ?
<?php
 
$divContent = "Directory";
 
if($myConditionIsMet) { # put your condition here
    $divContent = "newDivContent" ;
}
 
 
?>
 
<html>
<body>
<div id="news_archive_head_title"><?php echo $divContent; ?></div>
</body>
</html>

Open in new window

0
 
Michael701Commented:
can you post your code and an example (before and after html) that didn't work?
0
 
käµfm³d 👽Commented:
Is

    $html = preg_replace('|\<div\sid="news_archive_head_title"\>.*?\</div\>|siu',$newdiv,$html);

what you're looking for?
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now