Michael D.
Michael D.

Reputation: 41

Remove text before first occurrence of a substring

I want to delete the other texts before the first <tr class="vcard agent"> in a document.

Note: There are multiple <tr class="vcard agent"> s in the document.

Upvotes: 3

Views: 2100

Answers (3)

Pradeep
Pradeep

Reputation: 1254

$answer = strstr($oriString,'<tr class="vcard agent">');

See strstrDocs.

Upvotes: 5

gpojd
gpojd

Reputation: 23065

Something like this might work:

preg_replace('/.*?<tr class="vcard agent">/', '<tr class="vcard agent">', $string);

Edit: Pradeep's answer looks like it is the best one.

Upvotes: 4

Adrian Serafin
Adrian Serafin

Reputation: 7715

$first = strpos($html, '<tr class="vcard agent">');
$result = substr($html, $first);

Upvotes: 1

Related Questions