Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

that might be something strange when I say that I want to encode a URL partially, But I am caught in this situation and it seems that I got no other solution...

here is my code snippet

    $url = isset($_GET['u']) ? esc_url($_GET['u']) : '';
        $image = isset($_GET['i']) ? $_GET['i'] : '';


   maybeappend = '<a href="?ajax=photo_thickbox&amp;i=' + encodeURIComponent(img.src) +
   '&amp;u=<?php echo urlencode($url); ?>&amp;height=400&amp;width=500" title="" 
    class="thickbox"><img src="' + img.src + '" ' + img_attr + '/></a>';

its taken from wordpress /wp-admin/press-this.php the issue is, I cant post to my site via Press this bookmarklet

I searched the google, studied the wordpress forums and found that I need to tweek Press this button in my bookmark tool bar in broswer..

but for me, that is not a solution,,why? obviously, I cant teach every visitor to do this change in their broswer..so I have to edit my code residing on server...

how can I edit encodeURIComponent(img.src) and <?php echo urlencode($url); ?> so it DOES NOT ENCODE HTTP:// part of url,

say I got a url 'http://www.google.com I want it to be encoded as www.google.com

any suggesion?

How can I achieve my goal? might be some regex ? (dont know regex :( )

what would be the code adjustment for this??

thanks for your help..

share|improve this question

3 Answers

First remove the http part using substr, then apply urlencode and then reattacht the http part.

Same method can be applied in JavaScript using the equivalent JavaScript functions.

$encoded = 'http://' . urlencode(substr($url, -7));
share|improve this answer

You could indeed use a regex to filter the http:// part of the url (which is, if I understood well, what you want to do).

Something like https?://(.*) should select the part of the url you want (the s? part takes into account potential secure links).

share|improve this answer

You'll want to make sure any matching strings are at the beginning of the strings

Javascript Use String.replace with regex:

url.replace( /^(http|https):\/\//, '' );

^ means start of the string

PHP Use str_replace(): php.net/str_replace

if( strpos( $url, 'http' ) == 0 ){
    str_replace( array( 'http://', 'https://'), '', $url, 1 );
}

strpos can also return a FALSE so make sure you use ==.

share|improve this answer
thanks, but I am not sure, how can I edit the code given above – N e w B e e Apr 20 at 19:38

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.