Sorry, I dont know much about java script. what i want is to replace the url 1.jpeg to 1-thumb.jpg but i cant get it working. please help. Thanks. <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <script type="text/javascript"> function getthumb(url) { var alink = url; var parts = alink.split("."); //split using dot as delimiter document.write(parts[0] + "-thumb.jpg"); } </script> </head> <body> <img src="javascript:getthumb('1.jpeg');"> </body> PHP:
function getthumb(url) { return url.replace(/(\d+)\.[a-z]{1,4}/, '$1-thumb.jpg'); } Code (javascript):