在 Laravel PHP 中获取子字符串

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42905429/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 15:37:01  来源:igfitidea点击:

Get a substring in Laravel PHP

phplaravelencryptionsubstring

提问by Anna Jeanine

I am currently trying to implement and edit form in my application where the default values are the ones from the item which need to be adjusted. My database encrypts some values and adjusted them before storing. What I need is to get the substring of 5 digits between the ://and .characters of the decrypted value. My form is formatted as:

我目前正在尝试在我的应用程序中实现和编辑表单,其中默认值是需要调整的项目中的值。我的数据库加密了一些值并在存储之前对其进行了调整。我需要的是获取解密值的://.字符之间的 5 位子串。我的表格格式为:

{!! Form::hidden('id', Lang::get('token.id')); !!}
{!! Form::text('id', Crypt::decrypt($token->url), ['class' => 'form-control', 'maxlength' => 5, 'placeholder' => Lang::get('token.id_placeholder')]); !!}

Could someone help me get the substring of 5 digits between ://and .from the decrypted value to use as a default value in my form?

可能有人帮助我得到的之间的5位数字的字符串://,并.从解密的值作为我的表单的默认值使用?

回答by Lucas Franco

you can do it this way:

你可以这样做:

<?php
$a = 'https://12345.test.com';
$digits = substr($a, strpos($a, '://') + 3, 5);

Hope it works.

希望它有效。

Edit:was missing part of the code

编辑:缺少部分代码