Build a link between some tags

I try to create links when a user write something in tags. But the problem is I cant convert the charset. like ş = s, ğ = g ... Here my code

$(document).ready(function () {
   $('em').html(function(i, linkle) {

var returnString = linkle.toLowerCase();
//Convert Characters
returnString = returnString.replace(/ö/g, 'o');
returnString = returnString.replace(/ç/g, 'c');
returnString = returnString.replace(/ş/g, 's');
returnString = returnString.replace(/ı/g, 'i');
returnString = returnString.replace(/ğ/g, 'g');
returnString = returnString.replace(/ü/g, 'u');  

// if there are other invalid chars, convert them into blank spaces
returnString = returnString.replace(/[^a-z0-9\s-]/g, "");
// convert multiple spaces and hyphens into one space       
returnString = returnString.replace(/[\s-]+/g, " ");
// trims current string
returnString = returnString.replace(/^\s+|\s+$/g,"");
// cuts string (if too long)
if(returnString.length > maxLength)
returnString = returnString.substring(0,maxLength);
// add hyphens
returnString = returnString.replace(/\s/g, "-");    

return '<a href="/' + linkle + '/">' + linkle + '</a>';
});
});

How can I convert chars and build my links. At last I want is if first and last char is blank clear it... Ty.

Answers


The jquery html() function expects a String but you are providing a function, you should move the function out of the html call and pass its return value instead. Also, you don't actually use the returnString variable when you are building your link, I think the return statement should read:

return '<a href="/' + returnString + '/">' + returnString + '</a>';

You might also consider just using encodeURI rather than replacing characters manually - this will convert the invalid characters so that are safe for use in a url.


Need Your Help

AVCaptureSession working fine on iPad but not on iPhone

ios objective-c iphone ipad avcapturesession

I am trying to make a video recording app using AVCaptureSession.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.