Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

STR Replace PHP Wordpress

Posted on 2014-09-15
4
Medium Priority
?
172 Views
Last Modified: 2014-09-15
How would I take into consideration two different Strings I would like to replace? The following code will remove the words Custom Price - but I would like to add an additional phrase to that, so that it is looking for two different strings.  I have named the second string $sig_alt
								<?php $xyz = WC()->cart->get_item_data( $cart_item );
								// THE SIGNAL STRING
										$sig = "Custom Price -";
										$sig_alt = "Bicycle Info -";
										
										// THIS STATEMENT ACKNOWLEDGES THAT THE TEST DATA MIGHT NOT CONTAIN THE SIGNAL STRING
										$abc = $xyz;
										$abcb = $xyzb;
										// IF THE SIGNAL STRING IS FOUND IN THE TEST DATA
										if (strpos($xyz, $sig) !== FALSE) {
												$abc = str_replace($sig, NULL, $xyz);
										}
echo $abc; 											
								 ?>

Open in new window

0
Comment
Question by:rgranlund
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40323489
Generally speaking, you would use one str_replace() function call for each string that you want to replace.
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 40323503
Hmm... The manual indicates that this would work, too.

<?php 
$xyz = WC()->cart->get_item_data( $cart_item );

// THE ARRAY OF SIGNAL STRINGS
$sig = array
( "Custom Price -"
, "Bicycle Info -"
)
;

// THIS USES AN ARRAY OF "NEEDLES"
$abc = str_replace($sig, NULL, $xyz);
echo $abc;

Open in new window

0
 
LVL 7

Author Comment

by:rgranlund
ID: 40323679
@ Large Light bulb just turned on inside of my head.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 40323804
Shining brightly!

Thanks for the points and thanks for using EE, ~Ray
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

660 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question