Tuesday, November 9, 2010

PHP: Best way to extract text within parenthesis?

SkyHi @ Tuesday, November 09, 2010
parenthesis:
<?php

$text = 'ignore everything except this (text)';
preg_match('#\((.*?)\)#', $text, $match);

echo '
';
print_r($match[1]);
echo '
';



square bracket :

<?php
$text = 'ignore everything except this (text)';
preg_match('#\<(.*?)\>#', $text, $match);

echo '
';
print_r($match[1]);
echo '
';


REFERENCES
http://stackoverflow.com/questions/196520/php-best-way-to-extract-text-within-parenthesis