首页 \ 问答 \ PHP复杂的preg_match(PHP Complicated preg_match)

PHP复杂的preg_match(PHP Complicated preg_match)

这是一个很大的范围,但我一直在尝试preg_match和preg_replace,以努力做一些非常复杂的事情。

我正在尝试使用整个PayPal按钮代码并仅提取13位数的按钮ID号。 我已成功使用preg_replace来获取所有不需要的字符,并将代码暴露为混乱的一行。 不幸的是我也提取了等号 - 我假设我需要从这个新生成的字符串中提取一个值=。

我面临的第二个问题是,即使我可以在我创建的字符串中留下等号,也有两个以paypal按钮形式存在的值。 现在,我不知何故需要忽略第一个值,只抓住第二个我需要的id。

我这样做的唯一原因是因为PayPal似乎没有办法复制那个按钮ID。 相反,它会生成整个表单的代码,当您单击它时,它会自动突出显示整个表单代码,不允许您只是突出显示您想要的小部分。 我不得不这样做,以便让不懂代码的人更容易复制表单代码,将其粘贴到表单字段中,让网站自动获取该ID号,然后在我编写的另一个脚本中使用它。

到目前为止,我有这个:

<?php
$string = '';
$res = preg_replace("/[^a-zA-Z0-9]/", "", $string);
echo $res;
?>

当我将PayPal表单代码添加到顶部的字符串时 - 看起来像这样:

<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="D3DPV3Y2WSA4J">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

我得到这个:formtargetpaypalactionhttpswwwpaypalcomcgibinwebscrmethodpostinputtypehiddennamecmdvaluesxclickinputtypehiddennamehostedbuttonidvalueD3DPV3Y2WSA4JinputtypeimagesrchttpswwwpaypalobjectscomenUSibtnbtncartLGgifborder0namesubmitaltPayPalThesafereasierwaytopayonlineimgaltborder0srchttpswwwpaypalobjectscomenUSiscrpixelgifwidth1height1form

当然,我唯一需要的是第二个值:D3DPV3Y2WSA4J

我觉得我可以做更多的研究,并弄清楚如何留下等号,所以我的值看起来像:值=但我真的不确定我能跳过第一个值而只抓住第二。

这对我来说是一次很棒的学习经历 - 因为我不经常使用这样的代码,但是我希望获得更多的知识。 读过这篇文章的人,非常感谢你的时间!


It's a far reach but I have been experimenting with both preg_match and preg_replace in an effort to do something extremely complicated.

I am trying to take an ENTIRE PayPal button code and extract only the 13-digit button id number. I have successfully used preg_replace to get all of the unwanted characters out and expose the code as one line of a jumbled mess. Unfortunately I extracted the equals signs too-which I assume I will need to extract a value= from this newly generated string.

The second issue I face, is even if I can leave the equal signs in the string I have created, there are two values in a paypal button form. Now, I somehow need to ignore the first value and grab only the second which is the id I need.

The only reason I am doing this is because PayPal doesn't seem to have a way to copy just that button id. Instead it generates the code for the whole form and when you click on it, it automatically highlights the whole form code not allowing you to simply highlight the small portion you want. I am having to do this to make it simpler for someone who doesn't understand code to copy the form code, paste it in a form field and have the website automatically grab that id number then use it in another script I have written.

So far, I have this:

<?php
$string = '';
$res = preg_replace("/[^a-zA-Z0-9]/", "", $string);
echo $res;
?>

When I add the PayPal form code to the string at the top - which looks like this:

<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="D3DPV3Y2WSA4J">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_cart_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

I get this: formtargetpaypalactionhttpswwwpaypalcomcgibinwebscrmethodpostinputtypehiddennamecmdvaluesxclickinputtypehiddennamehostedbuttonidvalueD3DPV3Y2WSA4JinputtypeimagesrchttpswwwpaypalobjectscomenUSibtnbtncartLGgifborder0namesubmitaltPayPalThesafereasierwaytopayonlineimgaltborder0srchttpswwwpaypalobjectscomenUSiscrpixelgifwidth1height1form

And of course, the only thing I need from that is the second value: D3DPV3Y2WSA4J

I feel like I could do a little more research and figure out how to leave the equals signs in so I have the values all looking like: value= but I'm really not sure I will be able to skip the first value and grab only the second.

This is all a great learning experience for me - as I do not frequently use code like this but would love to gain more knowledge. Anyone who reads this, thank you so much for your time!


原文:
更新时间:2022-03-03 18:03

最满意答案

您可以使用以下方式签出特定版本的代码

git checkout <commit-hash>

您可以通过使用git loggitk获取<commit-hash>


You can checkout a specific version of the code using

git checkout <commit-hash>

You can obtain <commit-hash> through use of git log or gitk.

相关问答

更多
  • 要删除本地最后两个提交,我建议使用: git reset --hard HEAD^^ Rebase是一个完全不同的操作,不会帮助你。 To remove the last two commits locally I'd suggest using: git reset --hard HEAD^^ Rebase is a completely different operation that won't help you here.
  • 首先,使用git克隆资源库,例如: git clone git://github.com/facebook/facebook-ios-sdk.git 这将下载存储库的完整历史记录,因此您可以切换到任何版本。 接下来,更改为新克隆的存储库: cd facebook-ios-sdk ...并使用git checkout 更改为正确的提交: git checkout 91f25642453 这将给你一个警告,因为你不再是分支机构,而是直接转到一个特定的版本。 (这被称为“分离的HEAD”状态 ...
  • 我使用http://github.com/kbjr/Git.php它的工作! require_once('Git.php'); $repo = Git::open('gitphp'); // -or- Git::create('/path/to/repo') $repo->run(' config user.email "your email"'); $repo->run(' config user.name "your username"'); echo $repo->run(' log ...
  • 虽然JSON日期没有标准,但大多数JSON日期都以UTC表示。 时间值末尾的“Z”,遵循ISO 8601 ,表明情况如此: "date": "2015-04-27T03:58:52Z" 事实上,这是Json.NET默认的期望 ,尽管你可以配置它。 因此你需要做: DateTime now = DateTime.UtcNow; 你的计算应该是正确的。 这是因为DateTime减法运算符不考虑DateTime是本地还是UTC单位 ,只是假设它们在同一时区中即使不是。 更多细节在这里和这里 。 更新 ...
  • 请注意,提交永远不会替换旧提交,两个提交都保存为单独的版本。 如果您已经添加了一次文件,则除非您已将其删除,否则每次提交之前都不需要这样做。 Please note that making a commit will never replace your old commit, both commits are saved as separate versions. If you have added the files once, you need not do that every time befor ...
  • 让我们首先更好地理解您尝试使用的命令会做什么。 它不会“删除提交”; 它编辑了master on origin的历史,意图是新历史不会包含最新的提交。 或者换句话说,它将origin master移到你目前签出的那个之前 - 如果你当前已经签出了master ,如果你的当地master与origin的master同步,那么从master的历史中删除最近的提交的效果。 但是你得到的错误表明在当前错误之前没有提交。 如果你没有什么可以移动master ,那么你就无法移动master 。 当然,如果您要做的是删除 ...
  • 通常,由于Git跟踪内容( 任何内容),因此它不关心您添加到存储库的内容。 无论是文本文件(例如源文件),编译二进制文件还是其他二进制资源(如图像)。 在内部,Git以相同的方式处理所有这些。 您应该考虑这些图形是否是存储库的一部分 。 你描述它的方式,似乎他们确实是项目的一部分,因为其他文件依赖于它们。 此外,它们不能从存储库中已存在的文件创建(例如编译的二进制文件通常不包含,因为存储库包含编译它们的源代码)。 至于“膨胀”,是的,二进制文件通常比文本文件大。 因此,在存储库中具有许多二进制文件可以快速增 ...
  • 如果它是一个库,我建议通过git-submodule访问它。 例如,Zend Framework已经在Github上了。 如果你想要zf2,你可以使用以下命令将它添加到你的仓库: git submodule add https://github.com/zendframework/zf2.git path/to/library/dir git commit -m "Added Zend Framework submodule" 这应该使GitHub for Windows忽略该目录与Zend Framew ...
  • 清除差异的唯一方法是用力推动。 如果有多个人在同一个分支上工作,你最好让他们知道你正在重写历史。 假设这是你的最后一次承诺...... git reset --soft HEAD~ (undo password changes) git diff (make sure there are no changes that display the passwords) (stage/commit changes) git push origin +branch_name 遵循标准的安全预防措施,如果密码链接到 ...
  • 您可以使用以下方式签出特定版本的代码 git checkout 您可以通过使用git log或gitk获取 。 You can checkout a specific version of the code using git checkout You can obtain through use of git log or gitk.

相关文章

更多

最新问答

更多
  • h2元素推动其他h2和div。(h2 element pushing other h2 and div down. two divs, two headers, and they're wrapped within a parent div)
  • 创建一个功能(Create a function)
  • 我投了份简历,是电脑编程方面的学徒,面试时说要培训三个月,前面
  • PDO语句不显示获取的结果(PDOstatement not displaying fetched results)
  • Qt冻结循环的原因?(Qt freezing cause of the loop?)
  • TableView重复youtube-api结果(TableView Repeating youtube-api result)
  • 如何使用自由职业者帐户登录我的php网站?(How can I login into my php website using freelancer account? [closed])
  • SQL Server 2014版本支持的最大数据库数(Maximum number of databases supported by SQL Server 2014 editions)
  • 我如何获得DynamicJasper 3.1.2(或更高版本)的Maven仓库?(How do I get the maven repository for DynamicJasper 3.1.2 (or higher)?)
  • 以编程方式创建UITableView(Creating a UITableView Programmatically)
  • 如何打破按钮上的生命周期循环(How to break do-while loop on button)
  • C#使用EF访问MVC上的部分类的自定义属性(C# access custom attributes of a partial class on MVC with EF)
  • 如何获得facebook app的publish_stream权限?(How to get publish_stream permissions for facebook app?)
  • 如何防止调用冗余函数的postgres视图(how to prevent postgres views calling redundant functions)
  • Sql Server在欧洲获取当前日期时间(Sql Server get current date time in Europe)
  • 设置kotlin扩展名(Setting a kotlin extension)
  • 如何并排放置两个元件?(How to position two elements side by side?)
  • 如何在vim中启用python3?(How to enable python3 in vim?)
  • 在MySQL和/或多列中使用多个表用于Rails应用程序(Using multiple tables in MySQL and/or multiple columns for a Rails application)
  • 如何隐藏谷歌地图上的登录按钮?(How to hide the Sign in button from Google maps?)
  • Mysql左连接旋转90°表(Mysql Left join rotate 90° table)
  • dedecms如何安装?
  • 在哪儿学计算机最好?
  • 学php哪个的书 最好,本人菜鸟
  • 触摸时不要突出显示表格视图行(Do not highlight table view row when touched)
  • 如何覆盖错误堆栈getter(How to override Error stack getter)
  • 带有ImageMagick和许多图像的GIF动画(GIF animation with ImageMagick and many images)
  • USSD INTERFACE - > java web应用程序通信(USSD INTERFACE -> java web app communication)
  • 电脑高中毕业学习去哪里培训
  • 正则表达式验证SMTP响应(Regex to validate SMTP Responses)