php - convert string to uuid version 4 format [duplicate] - php

This question already has answers here:
Format 32-character string with hyphens to become UUID
(3 answers)
Closed 7 months ago.
I want convert this string to uuid4 by PHP functions
my string: 24:1D:87:0E:01:32:09:FB:36:97:23:BD:B5:E1:18:04
convert to : 241d870e-0132-49fb-b697-23bdb5e11804
how can do it?! php have function or?!...

You could do a combination of:
str_replace() to strip out the : colons
substr() the sections you need
and concat them with . "-" .
lastly apply strtolower() if that's really required
Or, you could write a regex/preg_replace transformation.

Related

Decode hex string to latin characters [duplicate]

This question already has answers here:
How to convert HTML entities like – to their character equivalents?
(5 answers)
Closed 7 years ago.
I have string:
tomas
there is decoded string tomas
I found that there is hec decode type : http://www.codetable.net/unicodecharacters
Does in PHP exists fuction to encode hex to latin characters ?
Those are not hex characters, but HTML entities.
PHP can decode them with html_entity_decode().

Convert special characters from PHP variables? [duplicate]

This question already has answers here:
PHP URL Encoding / Decoding
(4 answers)
Closed 8 years ago.
I can print a url with the following:
<?php print $base_url . $node_url ?>
What is the standard PHP way of converting special characters?
So instead of: http://time.com/3525666/ebola-psychology-fear-symptoms/
I need http%3A%2F%2Ftime.com%2F3525666%2Febola-psychology-fear-symptoms%2F
You would use urlencode for that sort of escaping.
Other escaping functions exist for other purposes, like htmlspecialchars for making text output safely for HTML display.
use his function in php , it is built in function to encode in url format
urlencode();
Just to add, htmlspecialchars, as mentioned above in the comment can take care of few html entities, not all of them.
Use htmlentities() instead:
$query_string = 'foo=' .urlencode($foo) . '&bar=' . urlencode($bar);echo '';

detecting chinese characters in php string [duplicate]

This question already has answers here:
Php - regular expression to check if the string has chinese chars
(4 answers)
Closed 8 years ago.
I am trying to detect chinese characters in a string I have in PHP, currently I am trying to do this:
$bio = '全部都好有用架 無用的我都一早打入冷宮唔見哂(… 有意/想睇圖都歡迎留whatsapp or line: chibimasakishop 可綠線/將軍澳線交收';
if (preg_match('/[\x{4e00}-\x{9fa5}]+.*\-/u', $bio) === 1) {
var_dump('contains a chinese character');
}
why isn't this working?
Try this
if(preg_match("/\p{Han}+/u", $bio))
{
var_dump('contains a chinese character');
}
Reference : Php check if the string has Chinese chars
in your case i think you have "\-" extra, i think
/[\x{4e00}-\x{9fa5}]+.*/u
should work

Convert Unicode escape sequence to UTF-8 [duplicate]

This question already has answers here:
Unicode character in PHP string
(8 answers)
Closed 2 years ago.
I'm trying to convert some characters with PHP before inserting to MySQL DB a JSON object with this kind of data:
\u00c9
that means: É
I tried this but it didn't work:
echo utf8_encode(print_r('\u00c9'));
I've read that it's in Unicode but i can't find the way to print it before inserting it. Any ideas?
Take a look at this answer. TL;DR:
echo json_decode('"\u00c9"');

PHP remove characters with hyphens above them like (é) [duplicate]

This question already has answers here:
Change foreign characters to their roman equivalent
(7 answers)
Closed 8 years ago.
Is there any possible way of doing this in PHP? Eg convert the word Québec
$str = 'Québec';
echo convert($str);
result:
Quebec
Those are called diacritics (or accents). The process of converting some text from one script to another (e.g. one with diacritics to one without) is called transliteration and PHP has a module for performing it.
You probably want something like:
transliterator_transliterate('Any-Latin; Latin-ASCII', $your_input);

Categories