PHP - Moved: Find And Replace
This topic has been moved to PHP Regex.
http://www.phpfreaks.com/forums/index.php?topic=328966.0 Similar TutorialsHi i wrote a find and replace code but my code replace last value of array and skip the first, second.... values in the array. Please give me an idea because i stack with this code. Regards $KeyWord = explode("\n", $RowGetWords['KEYWORDS']); $Replace = explode("\n", $RowGetWords['ReplaceTo']); for($i=0; $i<count($KeyWord); $i++){ $pattern = $KeyWord[$i]; $replace = "<a href=\"" .$URL. "\" target=\"_blank\" >" .$Replace[$i]. "</a>"; $html = str_replace($pattern, $replace, $Row['MessageBody']); } I have a long string of html, and what I want to do, if find all occurrences of: /static (anything after)... and replace with: http://www.mydomain.com/static (anything after). What is the best and fastest way to do this? Thanks. Hi ,, my frineds , how r u ? I have this article in my script: Quote <<WordPress>> widgets are the dynamic objects which eases the customization of the content on <<sidebars>> and widgetized <<footers>>. <<Widgets>> allows drag-n-drop interface in the Dashboard <<admin panel>>, for easy <<management>>. I want from the script , search about any word have <<..>> and replace it by: <a href="the word.php"> the word <a/> for examle : when the script find this word: <<Hello World>> , directly update it and replace PHP Code: <a href="hello-world.php"> Hello world </a> how can work it .. thank you very much for helping me .. ^_^ I have this code reads the xml runs with no errors but will not input the data from the array in the <catparent> The script Code: [Select] <?php // isbn => pages $page_numbers = array( '1234' => 'hello parent', // insert data into catparent node '5678' => 'hello parent', // insert data into catparent node ); $dom = new DOMDocument(); $dom->load('edtest1.xml'); $xpath = new DOMXPath($dom); $items = $xpath->query('item'); foreach($items as $item) { $catcode = $item->getElementsByTagName['catcode']; $parent_code = $page_numbers[ $catcode[0] ]; $item->appendChild( $dom->createElement('catparent', $parent_code) ); } $dom->save('edtest_stack.xml'); ?> My XML file looks like Code: [Select] <?xml version="1.0" encoding="UTF-8"?> <items> <item> <catcode>1234</catcode> <catdesc>Systems - System Bundles</catdesc> </item> <item> <catcode>5678</catcode> <catdesc>Hard Drives - SATA</catdesc> </item> </items> Output XML looks like this as you can see it has created the <catparent> but will not insert the data from the array. Code: [Select] <?xml version="1.0" encoding="UTF-8"?> <items> <item> <catcode>1234</catcode> <catdesc>Systems - System Bundles</catdesc> <catparent></catparent></item> <item> <catcode>5678</catcode> <catdesc>Hard Drives - SATA</catdesc> <catparent></catparent></item> </items> Any ideas pointers as to where I'm going wrong would be most helpful hello I've some code and I want remove text between Publisher: and >. This text is not fixed. anyone can help me to find text between two char and replace them with "" using php? thank you I'm trying to increment a numerical value and after several hours of reading haven't come up with a solution. this may be too much information but here it is; I'm using this code to change the values in r5include.html Code: [Select] <?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); ?> but before I do that I'm copying the original to a temp file with this code: Code: [Select] <?php $filename = 'r5include.html'; $string = file_get_contents($filename); $tempfile = 'temp.html'; $handle = fopen($tempfile, "a"); fwrite($handle,$string); fclose($handle); ?> This is what goes to temp.html: Code: [Select] <img height=75 src='images/up.jpg' hidefocus='true' usemap='#record51' /> <map name='record51'> <area shape='rect' coords='0,0,75,75' href='add.html' target='_blank'> I would like to increment the 2 instances of record51 to record52 and increment again each time the process is initiated. And then append it to r5include with this: Code: [Select] <?php $myFile = "r5include.html"; $fh = fopen($myFile, 'a') or die("can't open file"); $filename = 'temp.html'; $string = file_get_contents($filename); fwrite($fh,$string); fclose($fh); ?> So the question is is it possible? and if so how do I increment the record number? Thanks, I know this won't be possible with DOC, but it should be with DOCX. Basically I want to have someone write up a docx file using special tokens in certain places. Then my PHP would find and replace those tokens when the users needs to. It would create and serve a NEW docx file with the tokens replaced. Any ideas on this? I'm reading up on a ton of libraries, but nearly all of them, their examples don't work out of the box. Thanks! 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 Folks, I need to Find and Replace some words in Source HTML, which is saved in a PHP Variable. Example: Quote $html = '<img src="some_source" title="paintball mask Picture" alt="Image for Paintball Mask"> <strong> Best Paintball Mask</strong>'; Find Condition: I want to FInd word "Paintball Mask" in vairiable $html, only where if the word "Paintball Mask" is there in Htaml Tag <Strong> </Strong>. As you can observe in $html, we have "Paintball Mask" in <IMG> Tag also, i want to Skip this because I only Need to COnsider if the word "Paintball Mask" there in <strong></strong> or not. One the words is found in <strong></strong> tag, i need to replace that word, to make it a hyperlink. (I think this bit can be done with strreplace()) But how can i restict my search to only <strong></strong> tag? Let me give Data Again: Quote $html = '<img src="some_source" title="paintball mask Picture" alt="Image for Paintball Mask"> <strong> Best Paintball Mask</strong>'; Find What: Paintball Mask Find in Which Tag: <strong> </strong> Replace it with: <a href="/">Paintball Mask</a> can someone help me with the code? Cheers Natasha Thomas I wanted to replace a strings in a large text file .. what would be the fastest way ?! e.g the text file contains .. INSERT INTO `subjects` VALUES (1, 'some text here', 'some text here', 'some text here'); INSERT INTO `subjects` VALUES (2, 'some text here', 'some text here', 'some text here'); INSERT INTO `subjects` VALUES (3, 'some text here', 'some text here', 'some text here'); INSERT INTO `subjects` VALUES (4, 'some text here', 'some text here', 'some text here'); INSERT INTO `subjects` VALUES (5, 'some text here', 'some text here', 'some text here'); I wanted to replace the string " VALUES (1, " with "VALUES (" in each line .. I'm new in PHP so any response would be much appreciated .. thanks Im dealing with html links in a database where I need to execute a small piece of php code. Well mysql doesnt execute php code thats held in a table. The easiest way for me to do this is just add the links without the code, & set up a function that will replace anything I set to for example in my case a link lookin like this: http://mysite.com/index.php?page=offers&blah=blah&sid= needs to look like this; http://mysite.com/index.php?page=offers&blah=blah&sid=<?php echo $_SESSION['login']; ?> so I would need a function like <?php $replace('sid=','sid=<?php echo $_SESSION['login'];?> ?> something like that. And I know its possible & I could create a function like this but honestly right now I am so tired after working 12 hours im lazy dont want to think to hard while I know there are a lot of people out there that have a function like this already. If you dont have one & dont feel like writing one for me could you atleast point me in the right direction so I dont have to think to hard?! Thanks!! what im trying to do is take a youtube embed code find the URL code for that video and remove all other parts of the code keeping only the URL of the video after i get the URL by it self then replace the http://www.youtube.com/ part of the URL with http://i2.ytimg.com/vi/ to do this i know that i need something like this to get the URL of the video http://www.youtube.com/((?:v|cp)/[A-Za-z0-9\-_=]+) but how to only return just the URL is something idk how to do then use str_replace http://www.youtube.com/(?:v|cp)/" with http://i2.ytimg.com/vi/ so in the end im asking if anyone know how to remove all other codes i dont want and only keep the URL this may have to be done using "regex" im not sure as i dont know to much about regex and what it can do but does sound like it would help lol This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=351288.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=314913.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=319445.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=321641.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=306153.0 This topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=343073.0 This topic has been moved to PHP Regex. http://www.phpfreaks.com/forums/index.php?topic=306039.0 This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=350064.0 |