PHP - Finding What Is In Between 2 Values (similar To Str_replace)
Hello,
I need to be able to find what is inbetween 2 values in a string of text. For example, <?php $string="Hello and welcome to the site. Click [link]welcome.php[/link] here to continue to the site"; ?> So I need some method of searching the string to see what values are in between the [link] and [/link] which I will then deal with in my own way. I have a feeling that I could do this with explode, but I'm not really sure. Any advice? Thanks in advance Similar Tutorialsare all of the following same, or some same or all different: $variable="" $variable=0 $variable=NULL and which of the above will satisfy if(empty($variable)) { blah!; } hi is there a way of doing a str replace to look twice like at moment i have if find space replace with "-" PHP Code: Code: [Select] .str_replace(' ','-',($row['model'])) is there a way i can do if find twice $row['model if find space " " replace with "-" also if find "i30" replace with "10" is there a way i can try find another like if find " " replace with "-" also if find "130" replace with hello world?? thanks in advance I have a simple db with values. I want to find all duplicate values and rename them 1,2,3 - so if I have these values for a 'colour' field: pID / color 1 / brown 2 / blue 3 / red 4 / red 5 / brown ...would result in: 1 / brown1 2 / blue 3 / red1 4 / red2 5 / brown2 ...is this possible? I have a DB of data: article-id, section-id, subsection-id, article-text. When a row is fetched I am displaying article, section, subsection as <h3>, <h4>, <h5> and then text in a <p>. Before outputting the text I want to scan it for other articles, sections, or subsections it may reference then turn that reference into a hyperlink. I read the PHP documentation but I can't find anything that translates to the basic commands of instring, indexof, and left/mid/right. Example: 1. Article Name 100. Article 1, section 1 100.a article 1, section 1, subsection a Text blah blah blah 105.f blah blah blah
I want to find that 105.f and turn it into a link. All my articles, sections, and subsections are in the DB so I know I can use an array of the number values as my items to look for, but I can't figure out how to look. 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! 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? 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? 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). 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 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 $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 im trying to run a query which will get posts from the database that have tags similar to the current ones. Unfortunatly the echoed result isnt displaying as it should. $query = $link->query("SELECT t.*, p.* FROM ".TBL_PREFIX."topics t JOIN ".TBL_PREFIX."posts p ON (p.p_tid = t.t_tid) WHERE t.t_name = '".decode_url($_GET['t_name'])."' LIMIT 1") or die(print_link_error()); $row = $query->fetch(PDO::FETCH_ASSOC); $tag_query = $link->query("SELECT p_name FROM ".TBL_PREFIX."posts WHERE MATCH (p_tags) AGAINST ('".$row['p_tags']."' IN BOOLEAN MODE) ")or die(print_link_error()); $result = $tag_query->fetch(); foreach($result as $key => $value) { echo 'Name = '.$result[$key]['p_name'].'<br />'; } i have done a dump of result and it shows: Code: [Select] $ => Array (2) ( ['p_name'] = String(12) "File Updates" ['0'] = String(12) "File Updates" ) but there should only be one item in this array(p_name). I dont know where the second is coming from. The query has pulled the right results, it just isnt displaying it right. I 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; ?> 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? 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. 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\" /> 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); |