php - 获取变量内容和剥离变量以仅返回数字的函数
问题描述
尝试从 Woocommerce 注释的内容中提取运输跟踪号给客户,最终将其作为值传递给自定义字段
原始功能
function get_value( $comment, $parameters ) {
return $comment->content;
}
修改功能(不工作)
function get_value( $comment, $parameters ) {
$tracking_note = $comment->content;
$new_output = preg_replace( '/[^0-9]/', '', $tracking_note );
return $new_output->content;
}
解决方案
preg_replace 不会返回对象,另请参考:https ://www.php.net/manual/en/function.preg-replace.php 。
只需返回变量,如:return $new_output;
推荐阅读
- css - 使用 Grid 和 Flexbox 的响应式页面问题
- java - 在 Python 中使用 X509 证书签署信封,结果与 Java 相同
- download - 如何优化从 Google Colab 下载数据集的时间?
- csv - 使用 Tensorflow 和 Keras 训练高光谱数据
- python - Google Ads API ConversionTrackerService - 仅返回单次转化
- mysql - Multiple insert from hbs to MySQL express js
- sql - 显示最近的笔记
- mysql - 比较嵌套关系belongToMany Laravel中的withCount
- linux - Linux 上的 Cucumber 与 Windows 上的 Cucumber - 需要了解优缺点
- azure - 与简单的 async/await 相比,使用 urable Function 进行扇入/扇出的优势