Note that there are some explanatory texts on larger screens.

plurals
  1. POMake a local link global /test.php -> example.com/test.php
    text
    copied!<p>I've been working on a spider algorithm and have been having some issues with the links.</p> <p>example of how it works:</p> <p>got content from -> example.com/bob/index.php?page=funny+faces</p> <p>content is :</p> <pre class="lang-html prettyprint-override"><code>&lt;html&gt; &lt;a href="../jack/index.php"&gt; link 1 &lt;/a&gt; &lt;a href="/bob_more_info"&gt; link 2 &lt;/a&gt; &lt;a href="http://www.youtube.com"&gt; link 3 &lt;/a&gt; &lt;/html&gt; </code></pre> <p>pass content through get links function</p> <p>links function returned</p> <blockquote> <p>[0] = ../jack/index.php</p> <p>[1] = /bob_more_info</p> <p>[2] = <a href="http://www.youtube.com" rel="nofollow">http://www.youtube.com</a></p> </blockquote> <p>now I need to make these links urls by what page I got them on (example.com/bob/index.php?page=funny+faces)</p> <p>so </p> <blockquote> <p>[0] -> ../jack/index.php <strong>into</strong> example.com/jack/index.php </p> <p>[1] -> /bob_more_info <strong>into</strong> example.com/bob/bob_more_info</p> <p>[2] -> <a href="http://www.youtube.com" rel="nofollow">http://www.youtube.com</a></p> </blockquote> <p>What I am asking for is a function that can do the conversion. This is mine, but it's not always working and is becoming a pain. If you could edit it or write me a function it would be much appreciated. Thanks in advance.</p> <p>Here is my function currently:</p> <pre class="lang-cs prettyprint-override"><code>//example: //$newURL = URLfix("example.com/bob/index.php?page=funny+faces", "../jack/index.php"); function URLfix ($url, $ext) { if(is_valid_url($url."/")) { $url .= "/"; } $ar1 = explode("/", $url); if(count($ar1) == 1) { return $url."/".$ext; } $target = $ar1[count($ar1) - 1]; if($target == "") { return $url.$ext; } if(strpos(" ".$target, ".")) { $cur = ""; for($i = 0; $i &lt; count($ar1) - 1; $i ++) { $cur .= $ar1[$i]; $cur .= "/"; } return $cur.$ext; } return $url."/".$ext; } </code></pre>
 

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