Solved

String functions

Posted on 2003-12-06
3
291 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 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Showing multiple maps using PHP and Google Maps 12 38
Wordpress and Wufoo 1 37
$_GET call between URL 3 38
PHP Underscores vs. Directory separators 5 26
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
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…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

761 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