Alright well I tried solving it by myself, and this is what I came up with. NOTE: I realized that the number I want will always be after the first equals sign (=) and will either encompass the rest of the string or end at the first ampersand (&), so I used those chars instead: [code]if (strpos($referurl, '=')) $startpos = (strpos($referurl, '=')) + 1; if (strpos($referurl, '&')) { $endpos = strpos($referurl, '&'); $length = $endpos - $startpos; $topicid = substr($referurl, $starpos, $length); } else { $topicid = substr($referurl, $startpos); }[/code] So, now my question is, will that code set $topicid to 7383 if: [code]$referurl="http://mydomain.com/forums/index.php?showtopic=7383&pid=59790"[/code] or [code]$referurl="http://mydomain.com/forums/index.php?showtopic=7383"[/code] ?