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 8121563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:32:04+00:00 2026-06-06T05:32:04+00:00

I have PHP snippets like this ( snippet.php ): <?php $some_param = some_function(); ?>

  • 0

I have PHP snippets like this (snippet.php):

<?php 
    $some_param = some_function();
?>

<p>
    Text, bla bla bla... <?php echo $some_param ?> other text
    more text
</p>

I load these snippets like this:

$html = file_get_contets('snippet.php');
$dom = new DOMDocument('1.0');
$dom->loadHTML($html);

and modify using xpath:

$xpath = new DOMXPath($dom);
foreach ($xpath->query("//text()") as $q) {
    $str = trim($q->nodeValue);
    if (isset($strings[$str])) {
        $q->nodeValue = translate($str);
    }
}

The problem comes when I try to save this file:

$dom->save($out);

It destroys completly the snippet structure:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w3.org/TR/REC-html40/loose.dtd">
<html><head><?php
    $some_param = some_function();
??></head><body><p>
    Translated text, bla bla bla... &lt;?php echo $some_param ?&gt; other text
    more text
</p></body></html>

What can I do to restore the original snippet structure when saving?

  • 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-06-06T05:32:07+00:00Added an answer on June 6, 2026 at 5:32 am

    The PHP Snippets are Processing Instructions. You can query them with XPath:

    //processing-instruction('php')
    

    The node test text() is true for any text node. For example, child::text() will select the text node children of the context node. Similarly, the node test comment() is true for any comment node, and the node test processing-instruction() is true for any processing instruction. The processing-instruction() test may have an argument that is Literal; in this case, it is true for any processing instruction that has a name equal to the value of the Literal.

    How to add them to a document is explained in

    • how to add php tags with the dom parser
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this code snippet in an email layout: <div> <?php echo $this->Html->image('Layouts/default/Logo.png', array(
I have PHP scrip that goes like this: if ($cost_frm < $cost){ echo <script
I have index.php like this: <script type=text/javascript src=jquery-1.4.2.js></script> <script type=text/javascript src=ajax.js></script> <a href='one.php' class='ajax'>One</a>
I have this PHP snippet: <?php $colors = array('red','green','blue'); foreach ($colors as &$item) {
have a php code like this,going to convert it in to C#. function isValid($n){
I say PHP, because I have this snippet to count the words with PHP,
In my javascript file, I have a code snippet like: $('<form action=process.php method=POST>' +
Here's the thing. I hava a simple snippet in PHP like this regarding a
I have php scripts that do things like register, login, upload. I would like
Currently my AJAX is working like this: index.php <a href='one.php' class='ajax'>One</a> <div id=workspace>workspace</div> one.php

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.