Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4547976
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:09:52+00:00 2026-05-21T16:09:52+00:00

I am trying to find a way to search through a page in php

  • 0

I am trying to find a way to search through a page in php to replace the names of form elements.

I guess I should explain. I’m doing a job for a friend and I want to make an easy database updater that is robust and can withstand adding elements without the person knowing much about php or databases.

In short, I want to search through a form and replace all the name=”%name%” with the respective database table key names, so I can use a simple foreach method to update the table.

So I was looking at the DOMDocument element to open an html page and replace every form name inside in order with the corresponding table keys, but I wasn’t sure if I can open a php page with loadHTMLfile or not. And, if I could open up a php page, would opening itself cause an infinite loop? Or would it just parse the html as if it were looking at client-side html?

Is there any way to do what I want? If not, that’s OK, I’ll just make it a little less awesome, but I was just wondering.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T16:09:53+00:00Added an answer on May 21, 2026 at 4:09 pm

    It’s perfectly doable.

    The DOMDocument is possibly the ideal (native) tool for this task, but you’ll probably want to look into the DOMDocument::loadHTML() method instead of the loadHTMLfile() one.

    To get the processed PHP page into a string, you can request the page with CURL, file_get_contents() or a similar alternative. This involves making an additional request and adding specific control logic to avoid an endless loop.

    A better alternative might be to use output buffering, here is a simple example I have at hand in how to replace the contents of the <title> tag:

    <?php
    
    ob_start();
    
    echo '<title>Original Title</title>';
    
    /*    get and delete current buffer      &&  start a new buffer */
    if ((($html = ob_get_clean()) !== false) && (ob_start() === true))
    {
        echo preg_replace('~<title>([^<]*)</title>~i', '<title>NEW TITLE</title>', $html, 1);
    }
    
    ?>
    

    I am using preg_replace(), but you shouldn’t have any problems adapting it to use DOMDocument nodes. It’s also worth noticing that the ob_start() call must be present before any headers / contents are sent to the browser, this includes session cookies and so on.

    This should get you going, let me know if you need any more help.


    A generic DOMDocument example:

    <?php
    
    ob_start(); // This must be the very first thing.
    
    echo '<html>'; // Start of HTML.
    echo '...'; // Your inputs and so on.
    echo '</html>'; // End of HTML.
    
    // Final processing, the $html variable will hold all output so far.
    if ((($html = ob_get_clean()) !== false) && (ob_start() === true))
    {
        $dom = new DOMDocument();
    
        $dom->loadHTML($html); // load the output HTML
    
        /* your specific search and replace logic goes here */
    
        echo $doc->saveHTML(); // output the replaced HTML
    }
    
    ?>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've search through about 10 pages, can't find this question here. I'm trying to
I'm trying to find a way to search inside PDF files. I came accross
I am trying to figure out a way to search through posts' custom fields.
Trying to find a way to send a POST HTTPS request from Python to
I am trying to find a way to impelement a share button into my
I am trying to find a way to may a onclick javascript function execute
I'm trying to find a way to spilt a string into single words OR
I'm trying to find a way to buffer FileNames from a given directory in
I'm trying to find a way to list the (static) dependency requirements of a
I'm trying to find a way to validate a large XML file against an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.