Reputation: 436
Problem : I need u69ruczh as output this from below code
$string = '<a data-mce-href="{{file:u69ruczh}}" href="{{file:u69ruczh}}">pptexamples.ppt</a>';
Generated output :
Array ( [0] => Array ( ) )
I have tried below code :
$string = '<a data-mce-href="{{file:u69ruczh}}" href="{{file:u69ruczh}}">pptexamples.ppt</a>';
$url = preg_match_all('/href=[\{\{file:(.*?)\}\}]/', $string, $match);
print_r($match);
Please assist me where did it goes wrong
Upvotes: 0
Views: 51
Reputation: 2034
This could be done simply using below regex.
$url = preg_match_all('/file\:([a-zA-Z0-9]+)/', $string, $match);
Upvotes: 1
Reputation: 175
If this format is standard this solution should also get you the desired output:
$string = '<a data-mce-href="{{file:u69ruczh}}" href="{{file:u69ruczh}}">pptexamples.ppt</a>';
$arr = explode(":",$string);
$substr = $arr[1];
$subarr = explode("}",$substr);
$finalstr = $subarr[0];
echo $finalstr;
// Output: u69ruczh
Upvotes: 1