-1

I have a file with several text. In this text always exists a line with especific tags like this:

<cbc:UUID schemeName="CUFE-SHA384">c8c453a568280e8edfad6d6cc4121e3ac8ffc6709001b40a24bb4c0cfcdba8ced7a54a164c4c87d4b58a29fb626e9941</cbc:UUID>

I need to extract the string inside <cbc:UUID schemeName="CUFE-SHA384"></cbc:UUID>

Actually I have:

$pg = file_get_contents(pg.txt);
$tag = "<cbc:UUID schemeName="CUFE-SHA384">";
$result = strpos($pg, $tag);

But this does not bring me the string inside.

Any suggestions?

Thanks

Andres Zambrano
  • 23
  • 1
  • 10

1 Answers1

1

You can use regex in preg_match function to find your specific tag with any text inside, saving this text, he will be at key 1 of the result array.

<?php

$teste = '<cbc:UUID schemeName="CUFE-SHA384">c8c453a568280e8edfad6d6cc4121e3ac8ffc6709001b40a24bb4c0cfcdba8ced7a54a164c4c87d4b58a29fb626e9941</cbc:UUID>';

preg_match("/<cbc\:UUID\ schemeName\=\"CUFE\-SHA384\"\>(.*)\<\/cbc\:UUID\>/", $teste, $tag);
$text = $tag[1];
echo $text;
André Walker
  • 588
  • 10
  • 30