Jump to content

Modifying URL:s in SMF


denniso

Recommended Posts

Hi!

 

I'm trying to modify an URL string with preg_replace in my SMF board  ;D

($buffer contains all the HTML code for the web page)

 

There is some code for similar purposes already:

$buffer = preg_replace('/"' . preg_quote($scripturl, '/') . '\?((?:board|topic)=[^#"]+?)(#[^"]*?)?"/e', "'\"' . \$scripturl . '/' . strtr('\$1', '&;=', '//,') . '.html\$2\"'", $buffer);

 

It will replace all occurences of the URL http://chaimai.com/index.php?board=2.0  with http://chaimai.com/index.php/board,2.0.html

and http://chaimai.com/index.php?topic=1666.0 with http://chaimai.com/index.php/topic,1666.0.html

and http://chaimai.com/index.php?topic=1281.msg5110#msg5110 with http://chaimai.com/index.php/topic,1281.msg5110.html#msg

 

In the example above $scripturl is set to "http://chaimai.com/index.php"

 

I need to modify it (or make several calls to preg_replace) so it will

 

I know it's a lot to ask but I will really be greatful to any help in the right direction ... Thank You!

wai.gif

 

Regards Dennis

Link to comment
https://forums.phpfreaks.com/topic/37756-modifying-urls-in-smf/
Share on other sites

Try a callback:

 

<pre>
<?php
$urls = array(
	'"http://chaimai.com/index.php?board=2.0"',
	'"http://chaimai.com/index.php?topic=1654.0#new"',
	'"http://chaimai.com/index.php?action=dictionary;sa=details;id=83239"'
);

$scripturl = 'http://chaimai.com/index.php';

function fix_urls ($matches) {
	print_r($matches);
	list($url, $type) = $matches;
	switch ($type) {
		case 'board':
			// Regex...
		break;
		// ...and others.
	}
};

foreach ($urls as $url) {
	echo $url, ' => ';
	$url = preg_replace_callback('/' . preg_quote($scripturl, '/') . '\?(board|topic|action)[^"]+/', 'fix_urls', $url);
	echo $url, '<br>';
}
?>
</pre>

Link to comment
https://forums.phpfreaks.com/topic/37756-modifying-urls-in-smf/#findComment-180733
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.