【问题标题】:strtolower and similar functions with wordpress phpstrtolower 和 wordpress php 的类似功能
【发布时间】:2013-01-10 16:27:13
【问题描述】:

您好,我想通过以下代码了解如何使用 strlower 函数和 strtolower + str_replace 函数 - <?php echo get_the_author_meta('custom_field_35', $user->ID); ?>

这是我目前所拥有的,但它不起作用 -

 <?php
$str = "echo get_the_author_meta('custom_field_35', $user->ID);";
$str = strtolower($str);
echo $str; // Prints mary had a little lamb and she loved it so
?>

<?php $get_the_author_meta('custom_field_36', $user->ID) = strtolower(str_replace(",", "",$get_the_author_meta('custom_field_35', $user->ID))); ?>

如何将 strtolower 和 str_replace 与 get_the_author_meta 一起使用?

【问题讨论】:

  • 您不能将函数设置为这样的值。您必须应用 strtolower 和 str_replace,然后将结果存储在变量中。
  • @Marc B 我之所以这样,是因为我尝试了不同的方法,看看能否让它发挥作用。
  • 尝试这样的事情将是货物崇拜编程的标志。在没有真正理解原因的情况下做事。
  • @Supericy 你能解释一下我该怎么做或提供一个例子吗?
  • @Marc B 我对 php 或函数不太熟悉,所以是的,我只是在尝试该代码以查看会发生什么。不过,我仍然需要知道如何完成这项任务。您有任何相关信息或示例可以提供帮助吗?

标签: php wordpress function echo str-replace


【解决方案1】:

底部的 strtolower 和 str_replace 看起来不错,但不能分配给它: $get_the_author_meta('custom_field_36', $user-&gt;ID)

你最好只拥有:

&lt;?php echo strtolower(str_replace(",", "",$get_the_author_meta('custom_field_35', $user-&gt;ID))); ?&gt;

或将其放入变量中并回显:

&lt;?php $var = strtolower(str_replace(",", "",$get_the_author_meta('custom_field_35', $user-&gt;ID)));

echo $var; ?&gt;

【讨论】:

  • 您好,我尝试使用您的建议并收到此错误 - “致命错误:函数名称必须是...中的字符串”
  • 我拥有的代码是我在原始问题中放置的代码。我不得不从我的页面中删除代码,因为我不断收到错误。我基本上想做的是让作者元以小写形式回显,并使用另一个函数将其变为小写并删除逗号。
【解决方案2】:

好吧,看来我不需要回去学习基本的 PHP 语法规则了,我自己就能弄明白。

如果其他人想知道我是怎么做到的 -

<?php
      $f_states = get_the_author_meta( 'custom_field_35', $user->ID, true );
$f_pr = get_the_author_meta( 'custom_field_36', $user->ID, true );
?>
<?php Print(strtolower(str_replace(",", "",$f_pr))); ?> <?php Print(strtolower($f_states)); ?>

【讨论】:

    猜你喜欢
    • 2010-11-03
    • 1970-01-01
    • 1970-01-01
    • 2013-11-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多