Thanks.. I will read up on those functions :)
Josh
Main Topics
Browse All TopicsOK, so I am trying to make my own Dialectizer type thing (based on the concept behind http://rinkworks.com/diale
I am usually pretty PHP competent, but this time I have failed.
Basically what I need it to do, is get a URL, and replace any instance of abc with xyz. I got that far.
Heres are the things I can't figure out (not yet anyway),
It must convert all relative image and CSS links to absolute links pointing to where they should
It has to point all relative links through the dialectizer as well
So, I thought I would throw it out here and see if anyone could help me out with the code..
Heres my code so far:
<?php
if ($_GET['url']) {
// grab out put from page
ob_start();
include($_GET['url']);
$pagecontent = ob_get_contents();
ob_end_clean();
// modify output
$pagecontent = eregi_replace("http://" , 'index.php?url=http://', $pagecontent);
$pagecontent = eregi_replace("ing", "in'", $pagecontent);
$pagecontent = eregi_replace("and", "an'", $pagecontent);
$pagecontent = eregi_replace("for", "fo'", $pagecontent);
$pagecontent = eregi_replace("broken", "busted", $pagecontent);
$pagecontent = eregi_replace("what", "whut", $pagecontent);
$pagecontent = eregi_replace("ever", "evah", $pagecontent);
$pagecontent = eregi_replace("tion", "shun", $pagecontent);
$pagecontent = eregi_replace("potatoe", "tater", $pagecontent);
//etc..
// write output to page
echo $pagecontent;
} else {
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Dialectizer</title>
</head>
<body>
<form method="get" action="<?php echo($_SERVER['PHP_SELF'])
<input name="url" type="text" /><br />
<input name="submit" type="submit" value="Dialectize It!" />
</form>
</body>
</html>
<?php } ?>
Josh
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Heh, I looked at this at work today and wrote a partial solution, but.. guess it doesn't matter now.
<?
$scriptpath='href="dialect
$pagereading="http://www.e
preg_match("!(.*/)[^/]*?!"
$folder=$regs[1];
preg_match("!([a-z0-9_-]+:
$domain=$regs[1];
function callback_abhref($matches)
{
global $scriptpath;
echo "abhref: {$matches[1]}<br>";
return $scriptpath . urlencode($matches[1]) . '"';
}
function callback_href($matches)
{
global $folder,$scriptpath;
echo "href: {$matches[1]}<br>";
if (strpos($scriptpath,$match
return "FISH";
return $scriptpath . urlencode($folder . $matches[1]) . '"';
}
function callback_roothref($matches
{
global $domain,$scriptpath;
echo "roothref: {$matches[1]}<br>";
return $scriptpath . urlencode($domain . $matches[1]) . '"';
}
$string='
<a href="http://google.com/se
<a href="/index.php">Link text</a>
<a href="fish/monkey?page=fis
';
$a=$string;
$a=preg_replace_callback('
$a=preg_replace_callback('
$a=preg_replace_callback('
echo "<pre>" . htmlspecialchars($a);
Business Accounts
Answer for Membership
by: SquinkyPosted on 2004-11-25 at 03:05:21ID: 12673564
For a start I'd suggest that you build arrays of match patterns and replacements so you can do it all in one pass. It will be much faster:
href\s*=\s *")(.*)(") /i', '$1index.php\?url=$2"$3', $pagecontent);
$in=array('ing', 'and', 'for'); //etc
$out = array('in', 'an', 'fo');
$translation = preg_replace($in, $out, $pagecontent);
You only need to redirect <a> tag links through your script, so your search for "http" etc is too wide. Try:
$pagecontent = preg_replace('/(<\s*a\s+.*
This also copes with links where the href is not the first attribute in an a tag, varying spacing, case insentitive.
You still need to convert images and CSS style or link meta tags to absolute URLs, along with form submission actions - I'll leave that for someone else, but you might find parse_url() and realpath() useful.