PHP find text between

Hi,

I am using a different version of Linux. I have moved a php site from Ubuntu to SL6. However I cannot get the following php function to work, that previously worked in Ubuntu,

The line is $lineuid = getTextBetweenTags('return', $output, 1);

I want to look at a returned xml string and find the value between <return> and </return>

Whats the best way to do this?
LVL 6
mark_06Asked:
Who is Participating?
 
Ray PaseurCommented:
Read this, http://php.net/manual/en/language.types.array.php

... then please take a look at these two lines of code from your sample above:

var_dump($lineuid[1]);
echo $lineuid;

Open in new window

In the first line, we use var_dump() to show the data element that you need.  It shows one of the elements of the array.  In the second line, we use echo to print out an array.  Since arrays consist of multiple data elements (grouped together under an array name) you do not know what you might get from using echo to print this variable.  If you use the right notation to access the element you need, you will get the right results.
0
 
Dave BaldwinFixer of ProblemsCommented:
'getTextBetweenTags' is not a PHP function so it must be a custom function written for you application.  You might need to change some code in 'getTextBetweenTags' because of different version of PHP.  We would need to see the code in that function to help you.
0
 
Ray PaseurCommented:
Something like this might work, and I agree with Dave - it would be good to have a look at the original code.
http://iconoun.com/demo/temp_mark_06.php

<?php // demo/temp_mark_06.php

/**
 * ... find the value between <return> and </return>
 * See http://www.experts-exchange.com/Programming/Languages/Scripting/PHP/Q_28637580.html
 */
error_reporting(E_ALL);

$txt = '<return>We can find this text</return>';
$rgx
= '#'                // REGEX DELIMITER
. preg_quote('<return>')
. '(.*?)'            // CAPTURE GROUP
. preg_quote('</return>')
. '#'                // REGEX DELIMITER
;

preg_match($rgx, $txt, $mat);
var_dump($mat[1]);

Open in new window

0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

 
mark_06Author Commented:
Hi Ray,

That works thanks, the only thing is it is including the first <return> in the output. How do I remove this?
0
 
Ray PaseurCommented:
This does not happen in my example, shown here.  Did you maybe make some changes?  This is why we want to see your code!
http://iconoun.com/demo/temp_mark_06.php
0
 
mark_06Author Commented:
This is the output:

<return>{D87FCFC5-117F-CE70-8306-0FB38D40BF4C}</return>{D87FCFC5-117F-CE70-8306-0FB38D40BF4C}

my code is this

$output = <?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><ns:addLineResponse xmlns:ns="http://www.cisco.com/AXL/API/10.5"><return>{0E5903EF-C18A-44C2-0941-818B1DCB871F}</return></ns:addLineResponse></soapenv:Body></soapenv:Envelope>

$rgx
= '#'                // REGEX DELIMITER
. preg_quote('<return>')
. '(.*?)'            // CAPTURE GROUP
. preg_quote('</return>')
. '#'                // REGEX DELIMITER
;

preg_match($rgx, $output, $lineuid);
var_dump($lineuid[1]);
echo $lineuid;

$file = 'print.txt';



file_put_contents($file, $lineuid);

I am looking to get the "{D87FCFC5-117F-CE70-8306-0FB38D40BF4C}" which is returned in a CURL soap request.I need this format from the XML output.

$ch = curl_init();
//curl_setopt($ch, CURLOPT_MUTE, 1);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POSTFIELDS, $xml);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);  
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($ch, CURLOPT_USERPWD, $u . ':' . $p);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
$output = curl_exec($ch);
echo("User $name with Extension $number has been added to Call Manager ");
echo $output;
curl_close($ch);
$file1 = 'print1.txt';
file_put_contents($file1, $output);
error_reporting(E_ALL);
//$lineuid = function getTextBetweenTags('return', $output, 1);
$rgx
= '#'                // REGEX DELIMITER
. preg_quote('<return>')
. '(.*?)'            // CAPTURE GROUP
. preg_quote('</return>')
. '#'                // REGEX DELIMITER
;

preg_match($rgx, $output, $lineuid);
var_dump($lineuid[1]);
echo $lineuid;

$file = 'print.txt';



file_put_contents($file, $lineuid);

Open in new window

0
 
mark_06Author Commented:
To give you some background I need it in that format so I can re-use it to submit another CURL SOAP request.
0
 
Terry WoodsIT GuruCommented:
The result you want is $lineuid[1] not $lineuid.
0
 
mark_06Author Commented:
Thanks, worked well with adding [1]
0
 
Ray PaseurCommented:
Thanks for the points, and going forward, please feel free to spread them around to all the experts who help -- I think Terry Woods provided good information here, too!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.