Solved

String functions

Posted on 2003-12-06
3
287 Views
Last Modified: 2008-02-26
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
Comment
Question by:drakkarnoir
3 Comments
 
LVL 24

Accepted Solution

by:
shivsa earned 300 total points
ID: 9890220
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
 
LVL 6

Assisted Solution

by:aolXFT
aolXFT earned 100 total points
ID: 9891897
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
 
LVL 3

Assisted Solution

by:red010knight
red010knight earned 100 total points
ID: 9893298
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

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to count occurrences of each item in an array.
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.

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now