Solved

STR Replace PHP Wordpress

Posted on 2014-09-15
4
169 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 110

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 110

Accepted Solution

by:
Ray Paseur earned 500 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 110

Expert Comment

by:Ray Paseur
ID: 40323804
Shining brightly!

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

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
These days socially coordinated efforts have turned into a critical requirement for enterprises.
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…

632 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