dongmiyi8220 2016-10-19 18:33
浏览 11

将php'strpos'仅应用于某些元素?

I have the following code to remove a string if it contains the word "from" for each product on the page. This works well, but I only want to delete it one place for each product. (The string exists in two places for each product.)

$sub_notags = strip_tags( $subscription_string );

if ( strpos( $sub_notags, 'From:') !== false )  {
    return '';
}

Here's the HTML output of the place where I want it to work:

<label class="product_checkbox">Add <span class="price-string">From $68.00 on October 3rd each year</span></label>

And here's the place I want to ignore:

<span class="price"><span class="price-string">From $68.00 on October 3rd each year</span></span>

Update: I tried using strstr instead of strpos, because PHP docs said that should "find the first occurrence of a string". But that isn't working either. It is still affecting all occurrences.

Update2: Here is $subscription_string:

// translators: 1$: recurring amount, 2$: month (e.g. "March"), 3$: day of the month (e.g. "23rd") (e.g. "$15 on March 15th every 3rd year")

$subscription_string = sprintf( __( '%1$s on %2$s %3$s every %4$s year', 'woocommerce-subscriptions' ), $price, $wp_locale->month[ $payment_day['month'] ], WC_Subscriptions::append_numeral_suffix( $payment_day['day'] ), WC_Subscriptions::append_numeral_suffix( $billing_interval ) );
                            }

And here's a var_dump of $subscription_string:

string(199) $68.00 on October 3rd each year
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 测距传感器数据手册i2c
    • ¥15 RPA正常跑,cmd输入cookies跑不出来
    • ¥15 求帮我调试一下freefem代码
    • ¥15 matlab代码解决,怎么运行
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法