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