Jump to content

preg_replace_callback problem


drisate

Recommended Posts

Hey guys i am trying to replace all the links in a var in to something else ...

Ex: http://google.com into http://mywebsite.ca?email=XX_EMAIL&nid=XX_ID&dat=http://google.com

 

What i have so fare is

 

function matche($matches){
$url = str_replace('http://', '', $matches[1]);
$url = str_replace('www.', '', $url);
return 'href="http://maplaza.ca?email=XX_EMAIL&nid=XX_ID&dat='.$url.'"';
}

$messages = preg_replace_callback("/href=['\"]([^'\"]+)['\"]/","matche",html_entity_decode($messages));

 

But for some reason it's not matching any link ...

 

Ex of texte in $messages after html_entity_decode :

                                    <table width="100%">
                                        <tbody>
                                            <tr>
                                                <td valign="top" height="20" align="center"><a href="http://mywebsite.ca/index.php" target="_blank"> 									<font face="verdana" color="white" size="2"> 									Politique de confidentialité</font></a></td>
                                            </tr>

                                            <tr>
                                                <td valign="top" height="20" align="center"><a href="http://mywebsite.ca/index.php?pageid=147&mod=nousjoindre" target="_blank"> 									<font face="verdana" color="white" size="2"> 									Communiquer avec nous</font></a></td>
                                            </tr>
                                            <tr>
                                                <td valign="top" height="20" align="center"><a href="http://mywebsite.ca/index.php?pageid=158" target="_blank"> 									<font face="verdana" color="white" size="2"> 									Annoncer sur mywebsite.ca</font></a></td>
                                            </tr>

                                        </tbody>
                                    </table>

 

As you can see http://mywebsite.ca/index.php?pageid=158 should be transformed into

http://mywebsite.ca?email=XX_EMAIL&nid=XX_ID&dat=mywebsite.ca/index.php?pageid=158

 

Any help would be apreciated...

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.