John Davidson

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

0 comments
Message:


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...



My Answer:
You can use the `str_replace()` function in PHP to remove forward slashes from a string within a variable. Here's an example of how you can do this:

php
$sku = $product->get_sku();
$sku = str_replace('/', '', $sku);

echo $sku;


This code will remove all forward slashes from the `$sku` variable and output the SKU without any slashes.

Rate this post

3 of 5 based on 8811 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us