473,385 Members | 1,872 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

str_replace for exact match

296 100+
Hello,

Expand|Select|Wrap|Line Numbers
  1. $x = "tyu"
  2.  
  3. $y="3"
  4.  
  5. $eq = "asa+tyu-tyut+1"
  6.  
  7. $result = str_replace($x,$y,$eq);
  8.  
  9. echo $result;

$result has "asa+3-3t+1"

I expect "asa+3-tyut+1"

Please help .
May 9 '08 #1
2 7322
dlite922
1,584 Expert 1GB
Hello,

Expand|Select|Wrap|Line Numbers
  1. $x = "tyu"
  2.  
  3. $y="3"
  4.  
  5. $eq = "asa+tyu-tyut+1"
  6.  
  7. $result = str_replace($x,$y,$eq);
  8.  
  9. echo $result;

$result has "asa+3-3t+1"

I expect "asa+3-tyut+1"

Please help .
That's pretty difficult to do, if not impossible unless you find some other pattern in your string.

use preg_replace() http://us2.php.net/preg_replace

to implent some kind of pattern...

for example

does it always end with t, those that end with "t" do not replace?

does it have to end with "-" everytime?

should it end with any characters except a through z?

This will help you find a regex that can do what you want.

I'm no regex expert but I think if it comes down to that and you have all your constraints, we can build one, experiment and make it work together.



-Dan
May 10 '08 #2
pankajit09
296 100+
That's pretty difficult to do, if not impossible unless you find some other pattern in your string.

use preg_replace() http://us2.php.net/preg_replace

to implent some kind of pattern...

for example

does it always end with t, those that end with "t" do not replace?

does it have to end with "-" everytime?

should it end with any characters except a through z?

This will help you find a regex that can do what you want.

I'm no regex expert but I think if it comes down to that and you have all your constraints, we can build one, experiment and make it work together.



-Dan

Yes you are right.

I am using -->

Expand|Select|Wrap|Line Numbers
  1. $eq = preg_replace("/\b".$param."\b/", $paramData, $eq);
May 12 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Mark Findlay | last post by:
I am trying to figure out how to set up my reg exp search so that the search will only match on the exact word. Here is the current problem code: Word1 = "RealPlayer.exe" Word2 = "Player.exe"...
0
by: NTPT | last post by:
Hi. i have table like this: create table my_data ( cond_1 int8,cond_2 varchar(),cond_3 .... cond_n whatrver ,data text) This table represents a simple tree structure with known max level...
1
by: marcomputers | last post by:
Hi, I'm trying to automatically update an existing rss podcast file using php and the str_replace function. Every time I add a media file, it should read the .rss file into a string, take the...
9
by: Wayne | last post by:
$a = $_POST; # txt_content = This is a<CR><LF>Test $p = str_replace ("%0D%0A", "<br>", $a); That is the above code that I am using, however, it is not picking up the CR/LF from the textarea. I...
4
by: The Numerator | last post by:
I have this page (print.php). In that file, I want to to include a text file from "songs/breathe.txt", and replace all instances of "<b" with "<span" and "</b>" with "</span>". I know how I should...
4
by: jmdaviault | last post by:
I want to do the equivalent of SELECT id from TABLE WHERE text='text' only fast solution I found is: SELECT id,text from TABLE WHERE MATCH(text) AGAINST('value' IN BOOLEAN MODE) HAVING...
2
by: Wayne Shu | last post by:
Hi everyone. In the following program, foo is an ambiguous call. #include <iostream> using namespace std; void foo(int *); void foo(int (&));
5
by: jmark | last post by:
I saw this example in php.net // Outputs: apearpearle pear $letters = array('a', 'p'); $fruit = array('apple', 'pear'); $text = 'a p'; $output = str_replace($letters, $fruit, $text);...
0
by: Rilly | last post by:
Anyone use PowerMovielist here? I have the 0.14 beta version. Do you have a problem where some shows you search for cause the fetch to hang ? I'm pulling my hair out on this.. For example, I search...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.