逻辑 菜鸟 简单的
我是想实现62进制的功能,可是下面这段代码只能echo出来,不能返回,不知道是什么原因,求高手解答function dwz($id,$str=""){ $a=array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"); $zs=(int)($id/sizeof($a)); $xs=$id%sizeof($a); if($zs>=sizeof($a)){ $str=$a[$xs].$str; dwz($zs,$str); } else{ if($str==""){ return $a[$zs].$a[$xs]; } else{ echo $a[$zs].$str;//这里只能输出 return $a[$zs].$str;//返回没值,不知道什么原因 } }}for($i=999990;$i<=1000000;$i++){ echo dwz($i); echo "<br>";}
回复讨论(解决方案)
第7行 dwz($zs,$str);
没有承接返回
$str = dwz($zs,$str);
函数结束处还需要有 return $str;
if($zs>=sizeof($a)){ $str=$a[$xs].$str; dwz($zs,$str); //这里加入return: return dwz($zs, $str); }
第7行 dwz($zs,$str);
没有承接返回
$str = dwz($zs,$str);
函数结束处还需要有 return $str;
哈哈,可以啦,谢谢你的提醒和指导
这样写也可以,可逆的前不限长度
echo convert_62(999990); //4C8secho convert_62('4C8s', 1); //999990function convert_62($s, $mode=0) { $d = str_split('0123456789ABCDEFGHIJKLMNOPQRSTUVEXYZabcdefghijklmnopqrstuvwxyz'); $r = ''; if($mode) { $d = array_flip($d); for($i=0; $i<strlen($s); $i++) $r = bcmul($r, '62') + $d[$s{$i}]; }else { while($s) { $r = $d[bcmod($s, '62')] . $r; $s = bcdiv($s, '62'); } } return $r;}
这样写也可以,可逆的前不限长度
echo convert_62(999990); //4C8secho convert_62('4C8s', 1); //999990function convert_62($s, $mode=0) { $d = str_split('0123456789ABCDEFGHIJKLMNOPQRSTUVEXYZabcdefghijklmnopqrstuvwxyz'); $r = ''; if($mode) { $d = array_flip($d); for($i=0; $i<strlen($s); $i++) $r = bcmul($r, '62') + $d[$s{$i}]; }else { while($s) { $r = $d[bcmod($s, '62')] . $r; $s = bcdiv($s, '62'); } } return $r;}
受用了,谢谢你
这样写也可以,可逆的前不限长度
echo convert_62(999990); //4C8secho convert_62('4C8s', 1); //999990function convert_62($s, $mode=0) { $d = str_split('0123456789ABCDEFGHIJKLMNOPQRSTUVEXYZabcdefghijklmnopqrstuvwxyz'); $r = ''; if($mode) { $d = array_flip($d); for($i=0; $i<strlen($s); $i++) $r = bcmul($r, '62') + $d[$s{$i}]; }else { while($s) { $r = $d[bcmod($s, '62')] . $r; $s = bcdiv($s, '62'); } } return $r;}
不好意思,请问下为什么我把这个文件放在本地测试可以用,但是放在服务器上不能用,会提示找不到bcmod这个函数
嗯,这是 php_bc 扩展没加载的原因(php for win 是自动加载的)
你还可以检查一下 php_gmp 扩展是否已加载,用这个函数库也是一样的
嗯,这是 php_bc 扩展没加载的原因(php for win 是自动加载的)
你还可以检查一下 php_gmp 扩展是否已加载,用这个函数库也是一样的
真的没有加载,那怎么办啊?
我没服务器的权限
print_r(get_loaded_extensions());
看看都有些什么
print_r(get_loaded_extensions());
看看都有些什么
Array( [0] => date [1] => libxml [2] => openssl [3] => pcre [4] => zlib [5] => ctype [6] => curl [7] => dom [8] => filter [9] => ftp [10] => gd [11] => hash [12] => iconv [13] => json [14] => mbstring [15] => mcrypt [16] => mhash [17] => mysql [18] => SimpleXML [19] => SPL [20] => PDO [21] => posix [22] => Reflection [23] => session [24] => pdo_sqlite [25] => sockets [26] => SQLite [27] => standard [28] => tokenizer [29] => xml [30] => xmlreader [31] => xmlwriter [32] => zip [33] => apache2handler [34] => memcache [35] => mssql [36] => soap [37] => Zend Optimizer)
没权限就不好办了
就自己写吧,你不是也写了吗
没权限就不好办了
就自己写吧,你不是也写了吗
我写的那个有错,发现运算到后面就错了,然后就用了你的
还是没搞清楚我的那个错在哪里,为什么运算到后面就错了
大神,帮忙看下吧
function dwz($id,$str=""){$a=array("0","1","2","3","4","5","6","7","8","9","a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z","A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"); $zs=(int)($id/sizeof($a)); $xs=$id%sizeof($a); if($zs>=sizeof($a)){ $str=$a[$xs].$str; $str=dwz($zs,$str); } else{ if($str==""){return $a[$zs].$a[$xs];} else{return $a[$zs].$str;} } return $str;}
这是我根据你的提示改的,可以显示出来,但是我之前的算法有错,帮忙看下
终于可以了,谢谢大神
function dwz($s) { $d = str_split('0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVEXYZ'); $r = ''; while($s) { $r = $d[(int)($s%62)].$r; $s = (int)($s/62); } return $r;}

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.

ThebestpracticesforsendingemailssecurelyinPHPinclude:1)UsingsecureconfigurationswithSMTPandSTARTTLSencryption,2)Validatingandsanitizinginputstopreventinjectionattacks,3)EncryptingsensitivedatawithinemailsusingOpenSSL,4)Properlyhandlingemailheaderstoa


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Linux new version
SublimeText3 Linux latest version

WebStorm Mac version
Useful JavaScript development tools
