Jump to content

Using preg_match with strrpos


BSlepkov

Recommended Posts

The answer may be so simple that I've totally overlooked it, but I've been struggling to use preg_match with strrpos. Can it be done? If so, my coding would be a heck of a lot more efficient and elegant.

 

Basically, what I want to do is extract the first specific tag (<tr ... > or <li ... >) to the left of a string. The problem is not my regular express (#<(tr|li)[^<]*?>#i), just getting something like ...

    strrpos($some-xhtml-text, preg_match('#<(tr|li)[^<]*?>#i', $some-xhtml-text, $tag));

... to work.

 

Any takers?

 

Link to comment
Share on other sites

<?php
$text = '<tr>';
$big_number = strlen($text);
$res = ($x = min(($b = strpos($text, '<li'))===false ? $big_number:$b,($b = strpos($text, '<tr'))===false ? $big_number:$b))== $big_number ? false : $x;
echo var_dump($res);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.