FPDF Converting Apostrophes into Weird Characters - special-characters

I have this string passed from a JavaScript form:
4 H/M’s
Which gets posted to an array, called '$out' and is keyed by "blurb".
I use FPDF to output it, with MultiCell, like so:
$pdf->MultiCell(190,4,$out["blurb"]);
However, FPDF outputs this string:
4 H/M’s
I've tried
html_entity_decode($out["blurb"], ENT_QUOTES, "UTF-8")
but it doesn't seem to be working. Any suggestions?

Use iconv like this :
// put $str your sting to encode for FPDF
// put $myencoding value as you current encoding
function fpdf_encode($str,$myencoding='latin1') {
return iconv($myencoding, 'windows-1252', trim(utf8_decode($str)));
}

Related

How to convert PDF file to base64 string in ionic

im looking for a way to convert PDF File to base64 string .
i have tried with the ionic base64 plugin which works on Android but not for IOS.
i have also tried the below file plugin
this.file.readAsDataURL(“filepath”, fileName).then(
file64 => {
console.log('file in 64: ', file64);
the file64 returns this value == data:application/pdf;base64" and nothing else
}).catch(err => {
console.log('booooooo');
});
filepath looks like this == “file:///Users/venkatswamydandaboina/Library/Developer/CoreSimulator/Devices/9A8C76B7-F443-409E-8B62-377E7713DB67/data/Containers/Data/Application/D1AD60AE-D75C-4065-8B44-32470A3DA5DA/Library/NoCloud/”
but it doesnt returns base64 string it only returns “data:application/pdf;base64”.
Please help me out.
Thanks
data:application/pdf;base64 is the standard metadata that gets appending to the base64 format to indicate the type of the file.
Instead of checking this == xyz,
You can do file.includes('data:application/pdf;base64')

SCSS Processor Unicode Output Incorrect

I have tested this issue using Scout-App and Visual Studio Code on Windows 10.
Having just downloaded Font-Awesome 4.7.0 SCSS files and set up a project/workspace, I have noticed a problem with unicode output. As an example:
in the '_variables.scss' partial, we have:
$fa-css-prefix: fa;
$fa-var-music: "\f001";
and in '_icons.scss' partial, we have:
.#{$fa-css-prefix}-music:before { content: $fa-var-music; }
with an expected result of:
.fa-music:before { content: "\f001"; }
but the output is:
.fa-music:before { content: ""; }
So all the unicode values stored in variables are processed to 
Thus I am unable to correctly compile the correct output for a modified font-awesome CSS file.
I have tried placing UTF8 encoding at the top of each SCSS file but the issue is still unresolved.
For a quick test, this will produce the result described:
test.scss
#charset "UTF-8";
$fa-css-prefix: fa;
$fa-var-music: "\f001";
.#{$fa-css-prefix}-music:before { content: $fa-var-music; }
It seems by writing:
"\f0a9" ,
Scout will compile the unicode character.
But, if you use interpolation:
#{'"' + \f0a9 + '"'}
then Scout will compile to "\f0a9".
You can also use variables like
$escaped: \f0aa;
...
#{'"' + $escaped + '"'}
or:
$escaped: f0aa;
...
#{'"\\' + $escaped + '"'}
Remarks:
The compiled unicode character may become a problem to the browser in the content attribute. Therefore you want to give him the written hex code.
If you mess around with the backslash and the interpolation, see also here:
Sass variable interpolation with backslash in output

Codemirror get all lines as array

Is there a way in Codemirror to get all the lines in the editor, represented as an array? I know it is possible to iterate over each lines like so..
editor.eachLine(line => {
// do something with line
})
..but I'm looking for a way to just get all the lines, something like editor.allLines() or something..
With editor.getValue(separator) you can get all lines as a sting separated by the given separator - default is "\n".
Then you can turn your previously generated string into an array with string.split(separator)
function getAllLinesAsArray (codeMirror) {
return codeMirror.getValue().split('\n')
}
DEMO: https://codepen.io/quic5/pen/WLzJPx

Flutter Unicode Apostrophe In String

I'm hoping this is an easy question, and that I'm just not seeing the forest due to all the trees.
I have a string in flutter than came from a REST API that looks like this:
"What\u0027s this?"
The \u is causing a problem.
I can't do a string.replaceAll("\", "\") on it as the single slash means it's looking for a character after it, which is not what I need.
I tried doing a string.replaceAll(String.fromCharCode(0x92), "") to remove it - That didn't work.
I then tried using a regex to remove it like string.replaceAll("/(?:\)/", "") and the same single slash remains.
So, the question is how to remove that single slash, so I can add in a double slash, or replace it with a double slash?
Cheers
Jase
I found the issue. I was looking for hex 92 (0x92) and it should have been decimal 92.
I ended up solving the issue like this...
String removeUnicodeApostrophes(String strInput) {
// First remove the single slash.
String strModified = strInput.replaceAll(String.fromCharCode(92), "");
// Now, we can replace the rest of the unicode with a proper apostrophe.
return strModified.replaceAll("u0027", "\'");
}
When the string is read, I assume what's happening is that it's being interpreted as literal rather than as what it should be (code points) i.e. each character of \0027 is a separate character. You may actually be able to fix this depending on how you access the API - see the dart convert library. If you use utf8.decode on the raw data you may be able to avoid this entire problem.
However, if that's not an option there's an easy enough solution for you.
What's happening when you're writing out your regex or replace is that you're not escaping the backslash, so it's essentially becoming nothing. If you use a double slash, that solve the problem as it escapes the escape character. "\\" => "\".
The other option is to use a raw string like r"\" which ignores the escape character.
Paste this into https://dartpad.dartlang.org:
String withapostraphe = "What\u0027s this?";
String withapostraphe1 = withapostraphe.replaceAll('\u0027', '');
String withapostraphe2 = withapostraphe.replaceAll(String.fromCharCode(0x27), '');
print("Original encoded properly: $withapostraphe");
print("Replaced with nothing: $withapostraphe1");
print("Using char code for ': $withapostraphe2");
String unicodeNotDecoded = "What\\u0027s this?";
String unicodeWithApostraphe = unicodeNotDecoded.replaceAll('\\u0027', '\'');
String unicodeNoApostraphe = unicodeNotDecoded.replaceAll('\\u0027', '');
String unicodeRaw = unicodeNotDecoded.replaceAll(r"\u0027", "'");
print("Data as read with escaped unicode: $unicodeNotDecoded");
print("Data replaced with apostraphe: $unicodeWithApostraphe");
print("Data replaced with nothing: $unicodeNoApostraphe");
print("Data replaced using raw string: $unicodeRaw");
To see the result:
Original encoded properly: What's this?
Replaced with nothing: Whats this?
Using char code for ': Whats this?
Data as read with escaped unicode: What\u0027s this?
Data replaced with apostraphe: What's this?
Data replaced with nothing: Whats this?
Data replaced using raw string: What's this?

Can't unescape escaped string with ABAP

I want to escape this string in SAPUI5 like this.
var escapedLongText = escape(unescapedLongText);
String (UTF-8 quote, space, Unicode quote)
" “
Escaped string
%22%20%u201C
I want to unescape it with this method, but it returns empty. Any ideas?
DATA: LV_STRING TYPE STRING.
LV_STRING = '%22%20%u201C'.
CALL METHOD CL_HTTP_UTILITY=>UNESCAPE_URL
EXPORTING
ESCAPED = LV_STRING
RECEIVING
UNESCAPED = LV_STRING.
I changed the code in SAPUI5 to the following:
var escapedLongText = encodeURI(unescapedLongText);
This results in: (like andreas mentioned)
%22%20%e2%80%9c
If I want to decode it later in SAPUI5, it can be done like this:
var unescapedLongText = unescape(decodeURI(escapedLongText));
The unescape needs to be done, because commas (for example) don't seem to be decoded automatically.