How to extract strings

Source: Internet
Author: User
How to extract the string & nbsp; & lt ;? Xml & nbsp; version = '1. 0' & nbsp; encoding = 'gb2312 '? & Gt; & nbsp; & lt; orderNo & gt; 10000000779460 & lt;/orderNo & gt; & lt; orderResult & gt; 5 & lt;/extract a string
How can I set the string
  10000000779460 5   10000000779461 11
All data of the orderNo and orderResult labels in is extracted. Put them in two arrays respectively?
------ Solution --------------------
$str = "
 
 
  10000000779460
 
 
  5
 
 
  10000000779461
 
 
  11
 ";
htm;
preg_match_all("/<([^>]+)>([^<]+)<\/\\1>/U", $str, $matches);
$out = array();
foreach ($matches[1] as $key => $value) {
$out[$value][] = $matches[2][$key];
}
var_dump($out);

------ Solution --------------------
Isn't it a standard xml output?
$ S =" 10000000779460 5   10000000779461 11 ";
$ A = simplexml_load_string ($ s );
Print_r ($ );
------ Solution --------------------

// Xml file operations
$ SimXml = simplexml_load_file ('xmlpath ');
// Retrieve orderNo
$ OrderNo = array ();
Foreach ($ simXml-> orderNo as $ order)
{
$ OrderNo [] = (string) $ order; // directly convert to string for storage
}
// Retrieve orderResult
$ OrderResult = array ();
Foreach ($ simXml-> orderResult as $ res)
{
$ OrderResult [] = (string) $ res; // directly convert to string for storage, or convert to another;
}


I don't know if you want simple xml operations.
------ Solution --------------------
$ S = <TXT
  10000000779460 5   10000000779461 11
TXT;

$ D = array ('orderno' => 'Array _ order', 'orderresult' => 'arraresult ');
Preg_match_all ('# <(orderNo
------ Solution --------------------
OrderResult)> (. +) # U', $ s, $ r );

Foreach ($ r [1] as $ I => $ k) $ {$ d [$ k]} [] = $ r [2] [$ I];

Print_r ($ array_order );
Print_r ($ arraresult );
Array
(
    [0] => 10000000779460
    [1] => 10000000779461
)
Array
(
    [0] => 5
    [1] => 11
)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.