Prevent or encode ’ to ' [duplicate] - javascript

This question already has answers here:
How to replace Microsoft-encoded quotes in PHP
(6 answers)
Closed 6 years ago.
I had an issue. I do not want to insert ’ to the database.
Because when reading the ’ it will turn out with funny character.
Is there a way to prevent or encode ’ to ' when inserting to MySQL?

If you just want to replace that specific string why not just doing:
$encoded = str_repace("’","'",$input);

Related

Javascript popup link in php [duplicate]

This question already has answers here:
Quotes problem when passing value to Javascript
(2 answers)
PHP-generated javascript and quote marks
(7 answers)
javascript quotes inside quotes, string literal issue
(4 answers)
Double quote single quote not working in PHP/JavaScript [closed]
(1 answer)
Closed 4 years ago.
i have this php code:
echo "<div class='show-popup'><a class='button-popup-container-right' href='javascript:apri('popup.html');' target='_blank'><i class='far fa-play-circle'></i> ASCOLTA LA RADIO</span></a></div>"
but, when i click on the link the path is only "javascript:apri("
I have inserted this script in the footer of the page
function apri(url) {
newin = window.open(url,'Player','top=50, left=50,scrollbars=no,resizable=yes,width=400,height=550,status=no,location=no,toolbar=no,nomenubar=no');
}
Can anyone help me please?
href='javascript:apri('
The first ' marks the start of the attribute value. The second ' marks the end of the attribute value.
If you want to include ' as data then you need to either use " to delimit the attribute value or to escape the ' as &apos;.
You can avoid this problem by writing Unobtrusive JavaScript and binding your event handlers with addEventListener.

Parse text for hashtags and replace with links using JavaScript [duplicate]

This question already has answers here:
Best HashTag Regex
(9 answers)
Closed 7 years ago.
How to replace twitter style #hashtags with JavaScript?
I.e.
this is a #hashtag should become this is a #hashtag.
For PHP: Parse text for hashtags and replace with links using php
t = 'this is a #hashtag'
t.replace(/#(\w+)/g, '#$1')
Gives
this is a #hashtag

Remove Substring in Javascript [duplicate]

This question already has answers here:
How to remove text from a string?
(16 answers)
Closed 7 years ago.
In JavaScript, I need to find a substring between &J= and Key using regex and remove it from my url which could contain several substrings.
Here is my url:
SID=18608202881669&Act=432&Mode=1&CLk=T&Key58=6003&dotnetdll=TopCoConfigurator.dll&dotnetfunc=CasingSizeSummary&SID=18608202881669&F=&J=CasingSize/CasingSizeSummary.asp&Key58=6003&ccs_casingsizeid=6003
Thanks
You can learn Regular Expression here and code for your problem is:
Here you go:
SID="18608202881669&Act=432&Mode=1&CLk=T&Key58=6003&dotnetdll=TopCoConfigurator.dll&dotnetfunc=CasingSizeSummary&SID=18608202881669&F=&J=CasingSize/CasingSizeSummary.asp&Key58=6003&ccs_casingsizeid=6003";
var re = /&J=(.*?)&Key/;
SID = SID.replace(re, '');
alert(SID);
See Fiddle

Parsing JSON containing new line characters [duplicate]

This question already has answers here:
How do I handle newlines in JSON?
(10 answers)
Closed 8 years ago.
In my website I try to convert a string to JSON which contains a newline.
JSON.parse('{"hallo":"line1\r\nline2","a":[5.5,5.6,5.7]}');
This produces an "Unexpected token" error. Do I need to escape that somehow?
Yes, you should escape both \n and \r as they belong to the list of control characters. Full list of characters that need to be escaped can be found here. Your code would be
obj = JSON.parse('{"hallo":"line1\\r\\nline2","a":[5.5,5.6,5.7]}');
JSFiddle: link
Try:
JSON.parse('{"hallo":"line1\\r\\nline2","a":[5.5,5.6,5.7]}');

remove special character for a string using javascript? [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Remove commas from the string using javascript
I want to remove special character in my string while searching . MY string is "It's complicated".
I wnat to remove ' from my string.
Can anybody please help me??
"It's complicated".replace("'", "");

Categories