[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 296
  • Last Modified:

String functions

Are wildcards possible in string replace functions? Like could I do str_replace("somevalue","anothervalue","originalstring*"); ? or use _ in defining the number of characters?

Thanks in advance
0
drakkarnoir
Asked:
drakkarnoir
3 Solutions
 
shivsaCommented:
No.

You're going to want to look at regular expressions for what you're doing. Have a look at the following functions:

www.php.net/manual/en/function.preg-match.php
www.php.net/manual/en/function.preg-match-all.php
www.php.net/manual/en/function.preg-replace.php

0
 
aolXFTCommented:
str_replace("somevalue","anothervalue","originalstring*"); ? or use _ in defining the number of characters?

I don't really see what you are trying to do. If you wanted a wild card, surely it would be in the pattern. Surely you don't need wild-cards in the original_string.
0
 
red010knightCommented:
Well you could make the string a variable prior to puting it in the function and concattinate that way ie:

$evalString="originalSting"."blah";
str_replace("somevalue","anothervalue",$evalString);

or if you have an array of strings to check:
$evalStringArr[0]="blah";
$evalStringArr[1]="blah";
$evalStringArr[2]="blah";
$evalString=implode(" -- ",$evalString);

/*
string implode ( string glue, array pieces )

Returns a string containing a string representation of all the array elements in the same order, with the glue string between each element.

*/

$newString=str_replace("somevalue","anothervalue",$evalString);
$evalStringArr=explode(" -- ",$newString);

and whala, you have all your data in original piecemeal yeah only had to run the function once, simple and rather clean...
try it out,
Not sure if it does what you want, but it would come rather close;-)

Red010knight
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now