PHP - Str_replace Problem
Similar TutorialsI am making script that will include 2 files , 1. with the cracked hashes and 2. with the usernames and hashes 1. file is like : hash:salt:password , and 2. file is like is username:hash:salt I want that the script loop through the 1.. file with hash:salt:password and replace every hash:salt with the password in 2. file I have written something but it isnt working for me Code: [Select] <?php $usernames=file_get_contents('users.txt'); $cracked=file('cracked.txt'); foreach($cracked as $cracked_line){ $hashes_explode=explode(":",$cracked_line); $hash_salt="$hashes_explode[0]:$hashes_explode[1]"; $plain_password=str_replace($hash_salt,$hashes_explode[2],$usernames); print $plain_password; } print $plain_password; ?> Hi, I am converting a mysqli function to mysql SELECT strings. I basically have two arrays (I include with only one item a piece below for clarity). I want to replace the '?' in the first array values with the value in the second array. I know this should be an easy one and I'm missing something simple... Any help much appreciated. Code: [Select] $parts = array('AND (taxon.Genus LIKE ?)'); $params = array(' wasmannia%'); $arrayCount = count($parts); for ($i = 0; $i < $arrayCount; ++$i) { str_replace('?', $params[$i], $parts[$i]); } I have this $string=<span style=\"font-weight: bold;"> how can i replace the \" with " only i try this but didnt work str_replace("\\\"","\"",$string) The first two work perfectly. In the third, I tried to put them together in an array and nothing happens. Can anyone see what I am doing wrong? Thanks Code: [Select] <?php $ident = $_POST['ident']; ?> <?php $filename = 'r5include.html'; $string = file_get_contents($filename); $data = str_replace("add.html' target='_blank'","$ident.html' target='iframe2'","$string"); $handle = fopen($filename, "w+"); fwrite($handle,$data); fclose($handle); ?> <?php $ident = $_POST['ident']; ?> <?php $ident2 = ($ident . 2); $filename = 'r5include.html'; $string = file_get_contents($filename); $data = str_replace("'images/up.jpg'","'$ident/$ident2.jpg'","$string"); $handle = fopen($filename, "w+"); fwrite($handle,$data); fclose($handle); ?> <?php $ident = $_POST['ident']; ?> <?php $ident2 = ($ident . 2); $filename = 'r5include.html'; $string = file_get_contents($filename); $old = array("'images/up.jpg'","add.html' target='_blank'"); $new = array("'$ident/$ident2.jpg'","$ident.html' target='iframe2'"); $data = str_replace("$old","$new","$string"); $handle = fopen($filename, "w+"); fwrite($handle,$data); fclose($handle); ?> Hello All, I'm using php to auto-insert variables into a canonical url within the <head>. Here is my code: <link rel="canonical" href="http://www.mysite.com/page.php?IT=<?php print $item; ?>&IT2=<?php print $desc; ?>" /> I used this to replace "+" with " ". <?php $desc = str_replace ("+"," ",$desc); ?> The problem is i use the variables in different sections of the page were I don't want the "+" to appear. I only want the "+" to appear in the canonical url space. I'm sure there is an easy way, but not for me So to sum up: I want srt_replace code to be incorporated into the <?php print $desc; ?> code ONLY. Thanks in advance for any help! How can I add str_replace(" ", "-") to the following line: Code: [Select] echo "<p>" . $_SERVER['SERVER_NAME'] . "/" . strtolower(stripslashes($row['name'])) .".php</p>"; I have a bunch of provinces being displayed and want to replace spaces with - (for example British Columbia turns into www.domain.com/british-columbia.php so I can link to this file). more test -- ================================================================== this mobile text message is brought to you by at&t How can I get the red part removed? I tried: $endings = array('\n--\n==================================================================\nthis mobile text message is brought to you by at&t'); $CONTENT = str_replace($endings,"",$CONTENT); i put it in an array because i'll have to add more things later Hi... I read on php.net manual that its better to use str_replace than preg_replace. I used Code: [Select] $summary = clean($_POST['summary']); $summary = nl2br($summary); to convert the carriage return(is that the correct term?) to insert them into mysql. So naturally, i want them converted into <br> when i pull them from mysql. I used this: Code: [Select] $num_rows=mysql_num_rows($result); if($num_rows == 0){ } else{ for($x = 0; $x < $num_rows; $x++){ $row = mysql_fetch_assoc($result); $id = $row['id']; $position = $row['position']; $summary = $row['summary']; $order = array("\r\n", "\n", "\r"); $replace = '<br />'; $newstr = str_replace($order, $replace, $summary); But i got this error: Code: [Select] Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in /home/...php on line 310 Is it a syntax error? Thanx in advance... I am trying to learn PHP and am a novice so please excuse the stupid question but I have researched and attempted to find a solution for this and cant. Hoping someone can help me. I have the following code I am using within a Wordpress template... Code: [Select] <?php if (function_exists('simple_feed_list')) : ?> <?php $title = get_the_title(); str_replace("+", " ", $title); simple_feed_list('http://www.amazon.com/rss/tag/'. str_replace(" ", "+", $title) .'/new/ref=tag_tdp_rss_new_man?tag=search-20','limit=5&desc=yes&nofollow=yes&more=no'); ?> <?php endif; ?> I am trying to make it produce a RSS feed url from amazon that looks like this: http://www.amazon.com/rss/tag/ipod ibuds/new/ref=tag_tdp_rss_new_man?tag=search-20 note the space between ipod and buds, that is what I am trying to accomplish. Right now the space is being changed I think to a + sign which breaks the feed if the search term is more than one word. Can anyone help me fix this? I have tried removing the string replace part, etc with no luck I want to basically delete any word that ends with ... So.. If I have the following phrase: Elvis Pres... I want to remove the word Pres... entirely. Basically, something along the lines of... $myphrase = str_replace("Pres...",'',$myphrase); except that I never know what $myphrase will be, so the above won't work. Is it str_replace I need or something else? Hello friends, If we have link $x = "search engin"; <a href="google.com"><?=$x?></a> and we want to remove space btween (search engine) to be (search-engine) ineed we should use str_replace and we change the link to $manal = str_replace(" ", "-", trim($x)); <a href="google.com"><?=$manal?></a> It not working ? and only working if $manal = str_replace(" ", "+", trim($x)); why + not - ? and is there anyway else to replce space to - ? thanks $to_censor = array("f", "a", "e", "r", "c"); $new_censor = array("****", "****", "****", "****", "****"); $new = str_replace($to_censor, $new_censor, $description); Is it possible to do this without having to add a new **** in $new_censor when I add another censored word in $to_censor I sometimes have words thrown into my database with the following symbol: Code: [Select] … What I'm trying to achieve is this.. Anytime that symbol is found, replace it and all previous letters.. back to the first space encountered... with nothing. Make sense? If I had the sentence Code: [Select] "the lazy brown d..…, it should return for me "the lazy brown" If I was just replacing the weird code, it would be a simple str_replace, but not sure how to make the letters before the symbol (up to the first space) go away. Ideas? This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=331371.0 I am trying to replace some fields in a file using the following code Code: [Select] $test = array( 'NAME' => 'A N Other', //$mailName, 'MAIL' => 'someone@internet.com', //$mailEmail, 'TELE' => '01111111111', //$mailTel, 'BODY' => 'This is a test message', //$mailBody, 'TIME' => date('g:ia'), 'DATE' => date('l jS F Y'), ); $file = file_get_contents("./languages/en/messeges/new_message.txt"); $value = array(); foreach($test as $key => $val) { $value[] = str_replace('{'.$key.'}', $val, $file); } $file ="<pre>$file</pre>"; echo implode($file, $value); here is the contents of "./languages/en/messeges/new_message.txt" Quote New message received on {DATE} at {TIME} From: {NAME} Contact Number: {TELE} Email: {MAIL} ---------------------------------------------------------------------------- {BODY} ---------------------------------------------------------------------------- Can someone please help as its echoing the complete file for every instance, 1 at a time I have a row in my sql I had to remove quotes from a href links to import it into my database because it was a csv file and delimiters were quote so I made a script to remove them. But I made a script to remove them: $file = file_get_contents('ibf_forums.csv'); $file = str_replace('="','=^69^',$file); $file = str_replace('\"','\^69^',$file); $file = str_replace('"\ ','\^69^',$file); Now I need to put them back in. So I need to replace ^69^ in a database. If I use UPDATE it will over write it all without replace just a part of it. An example if I don't make sense: Code: [Select] Thanks! <img src=\^69^http://domain.com/style_emoticons/<#EMO_DIR#>/tongue.gif\^69^ style=\^69^vertical-align:middle\^69^ emoid=\^69^:P\^69^ border=\^69^0\^69^ alt=\^69^tongue.gif\^69^ />Into this: Code: [Select] Thanks! <img src=\"http://domain.com/style_emoticons/<#EMO_DIR#>/tongue.gif\" style=\"vertical-align:middle\" emoid=\":P\" border=\"0\" alt=\"tongue.gif\" /> Here's my code, a simple replace $newlink = str_replace("/http:\/\/images\.4chan\.org\/(.+)\/src\//", "thread/", "http://images.4chan.org/adv/src/1288558759794.png"); Print $newlink; I want it to output "thread/1288558759794.png", but its just giving me the link I started with. Any ideas whats wrong? Hi, I have the following text: Quote London, May 1: Hi there I am trying to remove everything till ':' The desired output is Quote %20Hi%20there I did this - Quote $np2 = "London, May 1: Hi there"; $i = array('-',' ','(.*):'); $j = array('','%20',''); $np = str_replace($i, $j, $np2); echo $np; I am unable to remove Quote London, May 1: Note: The word "London" could be anything, so I am trying to get a wildcard. Hi all. I have a query that returns field names. I'm basically just trying to clean these field names up. Removing underscores, capitalizing letters, etc. The following is supposed to replace underscores with spaces, but it doesn't seem to work. Any help is appreciated. str_replace("_"," ",$fields->name); What I want to do should be very simple, but I've stared at code all day and can't grasp it. I want to replace the "&" character, if it exists, with the "&" string. What I have is: Code: [Select] $name = $RESULT['ACCOUNT_NAME']; $cleaned = str_replace('&','& ', $name); echo $cleaned; It doesn't crash or anything, but it doesn't work. I have several ampersand (&) characters in my output that aren't getting replaced. Any help is appreciated. |