#1
  1. No Profile Picture
    Gone PHP Crazy
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Melbourne, Australia
    Posts
    393
    Rep Power
    12

    making javascript code through php function


    I got the following code to encrypt email addresses into a javascript code. As I have a few emails to encrypt while displaying on a web page I am trying to convert it to a php function. Here is the code:
    Code:
    <SCRIPT LANGUAGE="javascript">
    <!-- // Javascript Email Address Encoder
    //  by www.stevedawson.com
    
    	var first = 'ma';
    	var second = 'il';
    	var third = 'to:';
    	var address = 'jefferyfernandez';
    	var domain = 'yahoo';
    	var ext = 'com';
    	var fullname = 'Jeffery Fernandez';
    	
    	document.write('<a href="');
    	document.write(first+second+third);
    	document.write(address);
    	document.write('&#64;');
    	document.write(domain);
    	document.write('.');
    	document.write(ext);
    	document.write('?subject=Sales Enquiry "');
    	document.write('title="'+fullname +'"');
    	document.write('class="tablelisting"');
    	document.write('>'); 
    	document.write('<img src="images/icon_email.gif" border="0" /></a>');
    // -->
    </script>
    I would pass the email address via php code
    PHP Code:
    write_email($email="jefferyfernandez@yahoo.com"); 
    Could someone show me how to split the email address into different variables to write it as javascript.

    Thanks
    Jeffery
    Last edited by paCkeTroUTer; June 17th, 2003 at 02:45 AM.
    visit http://www.techsatcomputers.com
  2. #2
  3. Muhhnnn !!
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Apr 2003
    Posts
    1,530
    Rep Power
    89
    php is executed on the server side. There is no need for such a trick as nobody have access to your php code. If you want to have your variables cut in parts on the generated HTML, then just echo your javascript which will then be executed on the client..
  4. #3
  5. No Profile Picture
    Gone PHP Crazy
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Location
    Melbourne, Australia
    Posts
    393
    Rep Power
    12
    ummm I don't know if you understood what I was trying to achieve but here is what I managed in the end:

    PHP Code:
    <?php
    function write_email($email$fullname)
    {
    list(
    $Username$Domain) = split("@"$email);
        echo 
    "
        <SCRIPT LANGUAGE=\"javascript\">
            var first = 'ma';
            var second = 'il';
            var third = 'to:';
            var address = '
    $Username';
            var domain = '
    $Domain';
                
            document.write('<a href=\"');
            document.write(first+second+third);
            document.write(address);
            document.write('@');
            document.write(domain);
            document.write('?subject=Sales Enquiry \"');
            document.write('title=\"
    $fullname \"');
            document.write('class=\"tablelisting\"');
            document.write('>'); 
            document.write('<img src=\"images/icon_email.gif\" border=\"0\" /></a>');
        </script>
        "
    ;
    }
    ?>
    visit http://www.techsatcomputers.com

IMN logo majestic logo threadwatch logo seochat tools logo