Hi,
I am new to php. I am facing an algorithm problem where I have a string consisting of numbers like 097110107.... and this string needs to be broken in groups of 3 digits each such that 097110107 = [097] [110] [107] The length of string is a multiple of 3 of-course for equal length sub-groups and then each sub-group needs to be converted to the ASCII equivalent character like [097] [110] [107] = 'ank' and of-course all sub-groups will be less than 256 value as integer of 3 digits.
How do I do all this in php?
--
Thanks,
Ankit
string to int (ASCII) conversion problem
Moderator: General Moderators
-
softsolutions
- Forum Newbie
- Posts: 1
- Joined: Wed Dec 01, 2010 6:21 am
Re: string to int (ASCII) conversion problem
Code: Select all
<?php
$string = '097110107';
$parts = str_split($string, 3);
$result = '';
foreach ($parts as $part) {
$result .= chr($part);
}
echo $result;
?>- AbraCadaver
- DevNet Master
- Posts: 2572
- Joined: Mon Feb 24, 2003 10:12 am
- Location: The Republic of Texas
- Contact:
Re: string to int (ASCII) conversion problem
For fun:
Code: Select all
$old = '097110107';
$new = implode(array_map('chr', str_split($old, 3)));mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.