Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

String functions

Posted on 2003-12-06
3
Medium Priority
?
295 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
[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 Comments
 
LVL 24

Accepted Solution

by:
shivsa earned 1200 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 400 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 400 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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.
Suggested Courses

636 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