Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here you go: if eregi() fails to match, the $outdata assignment will never happen as the if block will not be executed. If it matches, but there's nothing between the tags, $outdata will be assigned an empty string. In both cases, !$outdata will be true, so we can fallback to a second match on the title tag instead.</p> <pre><code>if(eregi("&lt;linkto&gt;(.*?)&lt;/linkto&gt;", $string, $link_match)) { $outdata = $link_match[1]; } if(!$outdata &amp;&amp; eregi("&lt;title&gt;(.*?)&lt;/title&gt;", $string, $title_match)) { $outdata = $title_match[1]; } </code></pre> <p>I also changed the (.*) in the match to (.*?). This means, don't be greedy. In the (.*) form, if you had $string set to</p> <pre><code>&lt;title&gt;Page Title&lt;/title&gt; ... ... &lt;iframe&gt;&lt;title&gt;A second title tag!&lt;/title&gt;&lt;/iframe&gt; </code></pre> <p>The regex would match</p> <pre><code>Page Title&lt;/title&gt; ... ... &lt;iframe&gt;&lt;title&gt;A second title tag! </code></pre> <p>Because it tries to match as much as possible, as long as the text is between any and any other !. In the (.*?) form, the match does what you'd expect - it matches</p> <pre><code>Page Title </code></pre> <p>And stops as soon as it is able.</p> <p>...</p> <p>As an aside, this thing is an interesting scheme, but why do you need it? Pages can link to other pages and pass parameters via the query string:</p> <pre><code>&lt;a href="somescript.php?prevpage=Foo"&gt;...&lt;/a&gt; </code></pre> <p>Then somescript.php can access the prevpage parameter via the $_GET['prevpage'] superglobal variable.</p> <p>Would that solve your problem?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload