Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

STR Replace PHP Wordpress

Posted on 2014-09-15
4
Medium Priority
?
178 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
  • 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Go t…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

972 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