1

I am getting invalid html as out when i try to create link dynamically using regular expression using a pattern.

This is my function which creates link:

$message ="sddsdsd @@[Sanesh Sunny:ZGNjBQN9ac3K] dsdsdsd ";
    function convert_usertags_links($message,$extraParams){
            $tag_name = 'a'; //default a 
            $has_link = $new_tab = 0; //default no link
            $href = $target = $sel_id = $tag_col = "";
            $tag_col = 'tag_col';
            if(isset($extraParams['tag_name']) && $extraParams['tag_name']!="")
                $tag_name = $extraParams['tag_name'];
            if(isset($extraParams['tag_col']) && $extraParams['tag_col']!="")
                $tag_col = $extraParams['tag_col'];
            if(isset($extraParams['has_link']) && $extraParams['has_link']!="")
                $has_link = $extraParams['has_link'];
            if(isset($extraParams['new_tab']) && $extraParams['new_tab']!="")
                $new_tab = $extraParams['new_tab'];
            if(isset($extraParams['selector_id']) && $extraParams['selector_id']!="")
                $sel_id = $extraParams['selector_id'];
            $site_url = 'www.google.com/project/';
            if($has_link == 1)
                $href = " href='".$site_url."user/profile/$2' ";
            if($has_link == 1)
                $target = " target='_blank' ";
            /*
             * to match numbers only       
             */
            $pattern = "/@@\[([^:]*):(.*?)\]/"; 
            #$pattern = "/@@\[([^:]*):([0-9a-zA-Z]*)\]/";
            $matches = array();
            preg_match_all($pattern, $message, $matches);
            $output = preg_replace($pattern, "<".$tag_name." class='".$tag_col."' id='".$sel_id."_$2'".$href.$target." >$1</".$tag_name.">", $message);
            return $output;
        }

This functions works perfect in localhost but when i tried the same in my stagging server having site_url like "https://dsdsdsdsdsd.com/project" i am getting invalid html like:

<a class="tag_col" id="user_tag_link_ZGV3ZmZ9ac3K_ZGNjBQN9ac3K" href="&lt;a href=&quot;www.google.com/4thambit-v6/user/profile/ZGNjBQN9ac3K&quot; target=&quot;_blank&quot;&gt;www.google.com/4thambit-v6/user/profile/ZGNjBQN9ac3K&lt;/a&gt;" target="_blank">Sanesh Sunny</a>

The href contains another a tag inside... if i pass site_url as 192.168.1.X which is IP Adresss it is working fine but when i use "www" or ".com" inside sit_url the above invalid html is returned with another a tag inside href......

Any idea why this happening ? i tried few sites but no help....

Wolverine
  • 455
  • 3
  • 8
  • 26

0 Answers0