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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:29:41+00:00 2026-05-11T23:29:41+00:00

Here is a simple form I am using to send XML data in admin_xml.php

  • 0

Here is a simple form I am using to send XML data in admin_xml.php

<form name="review" action="admin_xml.php" method="post">
 <textarea name="xml" cols="40" rows="10"></textarea>
 <input class="submit" type="submit" value="Submit Request">
</form>

Here is the XML which I enter in order to retrieve the data from MySQL Database

<?xml version="1.0" encoding="UTF-8"?>
<GetOrdersIds>
    <Credentials>
        <Username>my_username</Username>
        <Password>my_password</Password>
    </Credentials>
    <Criterions>
        <OrderNumber></OrderNumber>
        <StartDate>2009-01-01</StartDate>
        <EndDate>2009-07-01</EndDate>
    </Criterions>
</GetOrdersIds>

Here is the php code which extracts the tags from the xml:

<?php    

$text_all = "<?xml version=\"1.0\"?>\r\n<GetOrdersIds version=\"1.0\">\r\n<Credentials>\r\n<Username>my_username</Username>\r\n<Password>my_password</Password>\r\n</Credentials>\r\n<Criterions>\r\n<OrderNumber></OrderNumber>\r\n<StartDate>2009-01-01</StartDate>\r\n<EndDate>2009-07-01</EndDate>\r\n</Criterions>\r\n</GetOrdersIds>";

$field = "Criterions";

$result = substr($text_all, strpos($text_all, "<".$field.">")+strlen("<".$field.">"), strpos($text_all, "</".$field.">")-strlen("<".$field.">")-strpos($text_all, "<".$field.">"));


?>

The result from the above php code is:

<OrderNumber></OrderNumber>
<StartDate>2009-01-01</StartDate>
<EndDate>2009-07-01</EndDate>

When the script is run, the php code goes through my mysql data, and extracts all orders between the Start Date and the End Date given above.


Is there a better way of improving the following php code, so that it performs the same function:

$result = substr($text_all, strpos($text_all, "<".$field.">")+strlen("<".$field.">"), strpos($text_all, "</".$field.">")-strlen("<".$field.">")-strpos($text_all, "<".$field.">"));

This is the code which searches through the xml data and retrieves all the tags.

UPDATE :

Can anyone list the $result code in SimpleXML?

  • 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-11T23:29:41+00:00Added an answer on May 11, 2026 at 11:29 pm

    Some temp vars will help and also make it easier to read.

    $result = substr($text_all, strpos($text_all, "<".$field.">")+strlen("<".$field.">"), strpos($text_all, "</".$field.">")-strlen("<".$field.">")-strpos($text_all, "<".$field.">"));
    

    Can be rewritten to.

    $tagLen = strlen('<'.$field.'>');
    $openTag = strpos($text_all, '<'.$field.'>');
    $closeTag = strpos($text_all, '</'.$field.'>', $openTag);
    
    $result = substr($text_all, $openTag + $tagLen, $closeTag - $tagLen - $openTag);
    

    or use SimpleXML

    $doc = simplexml_load_string($text_all);
    echo $doc->Criterions->asXML();
    

    If you want the individual values use this.

    $doc = simplexml_load_string($text_all);
    
    echo $doc->Criterions->OrderNumber;
    echo $doc->Criterions->StartDate;
    echo $doc->Criterions->EndDate;
    

    if you want the element in XML then use asXML():

    $doc = simplexml_load_string($text_all);
    
    echo $doc->Criterions->OrderNumber->asXML();
    echo $doc->Criterions->StartDate->asXML();
    echo $doc->Criterions->EndDate->asXML();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 121k
  • Answers 121k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Supposing you maintain a foreign key constraint between TABLE1 and… May 12, 2026 at 12:23 am
  • Editorial Team
    Editorial Team added an answer AFIK there is no standard way of doing this. Replication… May 12, 2026 at 12:23 am
  • Editorial Team
    Editorial Team added an answer Right click the setup project, and select "View" > "File… May 12, 2026 at 12:23 am

Related Questions

I am using XAMPP on a localhost windows VISTA m/c...using gmail as smpt server
I am trying to make a form with some dynamic behavior. Specifically, I have
I am trying to separate some asp logic out into a separate page. For
Ok, so I have a very simple form with next to no logic in
I have a task that I need to perform for a friend as a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.