How to code PHP function that displays a specific div from external file if div called by getElementById has no value? -


thank answering question quickly. did more digging , found solution grabbing data external file , specific div , posting document using php domdocument. i'm looking improve code adding if condition grab data different div if 1 called getelementbyid has data. here code got far.

external html source.

<div id="tab1_header" class="cushycms"><h2>meeting - 12:00pm 3:00pm</h2></div> 

my php file calling source looks this.

<?php  $source = "user_data.htm"; $dom = new domdocument(); $dom->loadhtmlfile($source); $dom->preservewhitespace = false; $tab1_header = $dom->getelementbyid('tab1_header');  ?>   <html>  <head>     <title></title> </head>  <body>  <div><h2><?php echo $tab1_header->nodevalue; ?></h2></div>   </body>   </html> 

the following function output message if div id can't found but...

if(!tab1_header) {     die("element not found"); } 

i call different div if 1 called has no data. meaning if <div id="tab1_header"></div> grab <div id="alternate"><img src="filler.png" /></div>. can me modify function above achieve result.

thanks.

either split master.php div1\2 in file each or set them each var, them include master.php, , use appropriate variable

master.php

$d1='<div id="description1">some text</div>'; $d2='<div id="description2">some text</div>'; 

description1.php

include 'master.php'; echo $d1; 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -