I confess that if it were not the example of how the string should look after captured and cleaned would have been almost impossible to answer.
And these "placeholders" [....] made it even more difficult.
Well, first you have to locate all the text, whatever it is until an end point:
preg_match( '/<p>(.*?\.).*?<\/p>/', $string, $text );
If you find this paragraph, the variable $text will have two indexes: In the first everything that was married and in the second only what is inside the <p>
.
Captured, you clean up:
preg_replace( '/\s\(.*?\)/', '', $text[ 1 ] );
Cleaning is done by locating a space, followed by an opening-parenthesis, with anything inside and a close-parenthesis.
Located this fragment, it is all removed and resulting astring:
Ola meu nome é pseudomatica, etc.
The complete code:
$string = '<div></div>
[........]
<p>Ola meu nome é pseudomatica (sou normal), etc. Meu nome é assim pq sim</p>
<p></p>
[........]';
if( preg_match( '/<p>(.*?\.).*?<\/p>/', $string, $text ) != 0 ) {
echo preg_replace( '/\s\(.*?\)/', '', $text[ 1 ] );
}
and how can I get a div from the class she owns?
– Vinícius Lara
That would be another question, but in order not to let you down, I suggest you read this guide. It is simply the best material about Regular Expressions available in Portuguese.
– Bruno Augusto