简体   繁体   中英

How do I remove slashes from a string within a variable?

The below code outputs product SKUs from my database exactly as they appear.

$sku = $product->get_sku();

Returns:

*BC01-BL/BL*

Given this context, how can I ensure that forward slashes are removed from $sku ? I've tried using stripslashes() but this does not work...

If you trying to achieve this *BC01-BLBL* , then you can use the str_replace() function:

<?php

$str = '*BC01-BL/BL*';
$str = str_replace("/", "", $str);
echo $str;
//returns *BC01-BLBL*

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM