How to extract part of a string in php
I use preg_replace () for some string replacement.
$str = "<aa>Let find the stuff qwe in between <id>12345</id> these two previous brackets</h>";
$do = preg_match("/qwe(.*)12345/", $str, $matches);
which works fine and gives the following result
$ match [0] = qwe in between 12345 $ match [1] = in between
but I use the same logic to extract from the next line.
<text>
<src><![CDATA[<TEXTFORMAT LEADING="2"><P ALIGN="LEFT"><FONT FACE="Arial" SIZE="36" COLOR="#999999" LETTERSPACING="0" KERNING="0">r1 text 1 </FONT></P></TEXTFORMAT>]]></src>
<width>45%</width>
<height>12%</height>
<left>30.416666666666668%</left>
<top>3.0416666666666665%</top>
<begin>2s</begin>
<dur>10s</dur>
<transIn>fadeIn</transIn>
<transOut>fadeOut</transOut>
<id>E2159292994B083ACA7ABC7799BBEF3F7198FFA2</id>
</text>
I want to extract a string from
r1text1
to
</id>
I have a regex:
preg_match('/r1text1(.*)</id\>/', $metadata], $matches);
where $ metadata is the line above.
Matches$ doesnβt return anything .... For some reason ... how can I do this? thanks in advance
If you want to extract text, you probably want to use preg_match. The following may work:
preg_match('#\<P[^\>]*\>\<FONT[^\>]*\>(.*\</id\>)#', $string, $matches)
, , $matches. <P>, <FONT> </id>, .
, , . , :)
, XML ( <![CDATA[ XML </id>, :
Amri :
/XML,/. ,>. :'/r1text1(.*)<\/id>/'#, :'#r1text1(.*)</id>#'( ).Rich Adams : "
r1_text_1" (_),'/r1text1(.*)<\/id>/'. ,'/r1(?:\s*)text(?:\s*)1(.*)<\/id>/'(?:- ).() .s(PCRE_DOTALL),.() :'/r1(?:\s*)text(?:\s*)1(.*)<\/id>/s'