0

Below is my code. PHP code

<?php
include('simple_html_dom.php');
$id=$_GET['id'];//Some URL like index.php
$dom = file_get_contents($id);
$html = file_get_html($id);
?>
<html lang="en" class="wide smoothscroll wow-animation">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>Update Content</title>
<meta name="description" content="" />
<meta name="keywords" content="" />
<meta name="format-detection" content="telephone=no"/>
<meta name="viewport" content="width=device-width, height=device-height, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"/>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" type="text/css" href="css/style1.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
</head>
<div class="container">
  <form class="form-horizontal">
    <div class="form-group">
      <label class="control-label col-sm-2" for="email">Page Name</label>
      <div class="col-sm-10">
        <input type="text" class="form-control" id="page_name" value="<?php echo $filename;?>" disabled>
      </div>
    </div>
    <?php 
foreach($html->find('meta[name=keywords]') as $element) {
?>    <div class="form-group">
      <label class="control-label col-sm-2" for="pwd">Meta Keyword</label>
      <div class="col-sm-10">
        <textarea class="form-control" id="meta_keyword"><?php echo $element->content; ?></textarea>
      </div>
    </div>
    <?php } 
    foreach($html->find('meta[name=description]') as $element) {
?>  
    <div class="form-group">
      <label class="control-label col-sm-2" for="pwd">Meta Description</label>
      <div class="col-sm-10">
        <textarea class="form-control" id="meta_description"><?php echo $element->content; ?></textarea>
      </div>
    </div>
     <?php } foreach($html->find('title') as $element) {?>
    <div class="form-group">
      <label class="control-label col-sm-2" for="pwd">Title</label>
      <div class="col-sm-10">
        <input type="text" class="form-control" id="title" value="<?php echo $element->innertext; ?>">
      </div>
    </div>
    <?php } foreach($html->find('h1') as $element) {?>
    <div class="form-group">
      <label class="control-label col-sm-2" for="pwd">H1</label>
      <div class="col-sm-10">
        <input type="text" class="form-control" id="h1" value="<?php echo $element->innertext; ?>">
      </div>
    </div>
    <?php } foreach($html->find('h2') as $element) {?>
    <div class="form-group">
      <label class="control-label col-sm-2" for="pwd">H2</label>
      <div class="col-sm-10">
        <input type="text" class="form-control" id="h2" value="<?php echo $element->innertext; ?>">
      </div>
    </div>
    <?php } foreach($html->find('h3') as $element) {?>
    <div class="form-group">
      <label class="control-label col-sm-2" for="pwd">H3</label>
      <div class="col-sm-10">
        <input type="text" class="form-control" id="h3" value="<?php echo $element->innertext; ?>">
      </div>
    </div>
    <?php } foreach($html->find('h4') as $element) {?>
    <div class="form-group">
      <label class="control-label col-sm-2" for="pwd">H4</label>
      <div class="col-sm-10">
        <input type="text" class="form-control" id="h4" value="<?php echo $element->innertext; ?>">
      </div>
    </div>
    <?php } foreach($html->find('h5') as $element) {?>
    <div class="form-group">
      <label class="control-label col-sm-2" for="pwd">H5</label>
      <div class="col-sm-10">
        <input type="text" class="form-control" id="h5" value="<?php echo $element->innertext; ?>">
      </div>
    </div>
    <?php } foreach($html->find('h6') as $element) {?>
    <div class="form-group">
      <label class="control-label col-sm-2" for="pwd">H6</label>
      <div class="col-sm-10">
        <input type="text" class="form-control" id="h6" value="<?php echo $element->innertext; ?>">
      </div>
    </div>
    <?php } ?>
    <br/><br/>
  <div class="form-group"> 
    <div class="col-sm-offset-2 col-sm-10">
      <button class="btn btn-lg btn-primary" id="content_submit" type="button" style="color:#fff">Submit</button>
    </div>
  </div>

  </form>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><script src="js/jquery.form.js"></script>

Refrence I used for this http://simplehtmldom.sourceforge.net/

Here I can Get all HTML elements with that code.And I want to modify the Same HTML element with Updated Text.But I don't get any reference from anywhere.Please is my page screenshot.

enter image description here

If I change something in that h3 textbox it will change in about.php <h3>New text</h3> How can I do this If anyone knows the solution Please help me to get out of this problem.Thanks in advance.

4
  • Can you reduce your problem to a simple statement with a small amount of reproducible code? Sounds like all you want is <script>$(function() { $("#h3").val("xxx"); }</script>. Please read this minimal reproducible example Commented Oct 17, 2016 at 13:17
  • I did not getting your question? Commented Oct 17, 2016 at 13:23
  • If I change some text in textbox corresponding to h3 tag.it will chang directly in about.php it will not happen lik as u answered Commented Oct 17, 2016 at 13:32
  • Can u please check the reference which I added in question.In that there will be a tab named modify HTML elements There thy specify How to change content inside div similarly I want to change content directly in specified page Commented Oct 17, 2016 at 13:34

1 Answer 1

1

I will show you for the first one $html->find('meta[name=keywords]'),You have to use a function __set from simplehtmldom, I am taking name of textarea as formss

foreach($html->find('meta[name=keywords]') as $element) {

$element->__set("content", "$_POST['formss']");

}

Please use different class or id for textarea, in a page there can be one meta keyword or title, but it can contain many h3 or h4 or h5. So use a for loop for that and it will make it easier for you. One more thing, why have you used $dom = file_get_contents($id); $html = file_get_html($id); two loading functions they will load the same thing and make your php execution slow.

Sign up to request clarification or add additional context in comments.

8 Comments

May I know similarly how can I Set content for title
First get title in a variable as you have done, and then use innertext instead of content in __set function
If multiple H3 tags is present in the webpage how can i set content?? Is there any way to find nth h1 tag and set content
You can use find function like find("h3",n) where n is number of h3. remember that find function create an array and than save all dom element to their respective position for a web page
Do you have any refrence link for this
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.