php - Finding and changing the value of a single "href" value using Simple Html DOM Library -
i need in parsing href attribute of single anchore tag , changing value in php file using "simple html dom" library. below html code:-
<li id="toggle"> <a id="open" class="open" href="#" style="display: block; "></a></li>
now want specific href value , change page say, logout.php depending upon if user logged in or not. , here php code:
<?php include 'simple_html_dom.php'; session_start(); $html = new simple_html_dom(); $html->load_file('index1.php'); if(!isset($_session['username'])){ $ret = $html->find('li[id=hello]'); $ret = "hello guest"; $tog = $html->find('li[id=toggle]'); $tog = "log in | register"; }else{ $user = $_session['username']; $ret = "hello " . $user; $tog = "log out"; $hrf = $html->find('a[id=open]'); $hrf->href = 'logout.php'; } ?>
now except finding , changing "href" value, other things working properly. welcomed. in advance.
now able solve problem. think both of overlooked fact returning array. did solve. may 1 else also.
$e = $html->find('a[id=open]'); // returns array containing info anchor $link = $e[0]->href; //the value of attribute href of anchor first element in array $e[0]->href = 'logout.php'; // new value $link = $e[0]->href; // assign value variable
Comments
Post a Comment