Solved

String functions

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

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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
PHP curl issue VERBOSE output 18 80
PHP not parsing ' character 12 46
Inserting data into database 10 34
Log in through ID 5 17
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
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…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to count occurrences of each item in an array.

765 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