Jump to content

AudiS2

Members
  • Posts

    22
  • Joined

  • Last visited

    Never

Everything posted by AudiS2

  1. If that helps I discovered that it is not that PHP crashes but just preg_replace, returning an empty string with /u. Still looking for ideas!
  2. Crash as in the script terminates, I assume because of mode not supported. But I can not find anywhere what are the requirements for /u searches
  3. I am using a regex with /iumsU modifiers. On some servers this crashes PHP and I need to turn UTF8 off thus the modifier becoming /imsU I am wondering how can I detect the requirements for /u to work normally so I can dynamically adjust my regex? Cheers
  4. My final solution was this: Replace the first img tag with iimmgg for example. perform strip_tags, return the changed tag back Thanks all!
  5. I am wondering is it possible to use strip_tags to only remove the first occurrence of the tag. I have html with multiple images and I want to strip it off html and but the first image.
  6. OK lets start preg_match('/\<link rel="alternate" type="application\/rss\+xml" title="(.*?)" href="(.*?)"/', $html, $matches); should fill the title and the link, but what if tags are in different order?
  7. Hi guys I searched for this. How to write a function that would return the RSS feed url (or list of URLs) for the given site ? I guess this comes down to loading the page and parsing it for 'link' tags with rel='alternate' attribute? For example feeds for phpfreaks.comare hidden in here. <link href="http://feeds.feedburner.com/phpfreaks" rel="alternate" type="application/atom+xml" title="Latest Content" /> <link href="http://feeds.feedburner.com/phpfreaks/tutorials" rel="alternate" type="application/atom+xml" title="Latest Tutorials" /> <link href="http://feeds.feedburner.com/phpfreaks/blog" rel="alternate" type="application/atom+xml" title="Latest Blog Posts" /><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> Can someone provide me with the code?
  8. Thanks Crayon . Copying seems to be only way. There is no function in PHP that says insert an element to an array at that position.
  9. Sorry I see now that my actual question was how to insert value between 'color' and 'size' so that at the end I have array('color'=>'green', "weight"=>"heavy", 'size'=>'big')
  10. Let say I have an example array('color'=>'green', 'size'=>'big') How can I insert 'weight'=>'heavy' at the beginning of array? array_unshift would not accept 'weight'=>'heavy' as a parametar.
  11. I have this code which does good job at finding words but it does not join up the results. I need to replace the whole found phrase with something. $needle = "pretty blue day"; $haystack = " It was blue and pretty day yesterday "; // explode into words $hwords = preg_split("/[\s\W]+/", $haystack); $nwords = preg_split("/[\s\W]+/", $needle); echo "Haystack: <br>$haystack<br><br>You searched for $needle<br>"; echo "I found...<br>"; foreach ($hwords as $hkey => $hayword) { $hmp = metaphone ($hayword); foreach ($nwords as $nkey => $needword) { // First or last letters of needle and haystack have to match (case insensitive) $nfirst = strtolower(substr($needword, 0, 1)); $nlast = strtolower(substr($needword, -1)); $hfirst = strtolower(substr($hayword, 0, 1)); $hlast = strtolower(substr($hayword, -1)); if (($hfirst == $nfirst) or ($hlast == $nlast)) { $nmp = metaphone ($needword); $distance = levenshtein ($hmp, $nmp); // $distance = levenshtein ($hayword, $needword); $n_len = strlen($nmp); $per = round(($distance/$n_len)*1000); if ($per < 335) { // Highlight word in haystack $haystack = str_replace($hayword, "<b>$hayword</b>", $haystack); $haystack = str_replace("<b><b>", "<b>", $haystack); $haystack = str_replace("</b></b>", "</b>", $haystack); } } } } // echo the new haystack echo $haystack;
  12. Task: Replace a string using advanced matching Example: $needle="pretty blue day" $haystack="It was blue and pretty day yesterday" Match "blue and pretty day", meaning the $needle can be permuted and additional words can be inserted in between (one or two words max, if possible this would be a setting).
  13. Ok found it in the thread: /(?!(?:[^<]+>|[^>]+<\/a>))\b(words)\b/is Thanks for the help and online regtester!
  14. Ok dsaba, good point. Let me explain it in more detail. In my particular case I need not to match a word that is a part of a link (<a>) but for other tags (<p>cars</p>) it should match them. Thing is I will be replacing the word with a link, and I do not want to do that for words that are already a part of a link (or html tag). I hope it is now more clear what I try to achieve.
  15. Hi gang, I need a regexp that will match my target word inside a text but not contained within any html tags. For example if the word is "cars" and text is: I love cars <a href="cars">cars</a> I want to match first but not the other two. Possible?
  16. I am wondering is there an implementation of parse_ini_file() that will work with a URL parameter for example parse_ini_file("http://www.example.com/example.ini") If not is there a version of parse_ini_file that takes a string as a parameter??
  17. How do I match filename with extension from url? http://server/dir/file.php -> file.php
  18. Effigy, thank you. Very elegant, with comments, perfect!
  19. I forgot to add that sometimes alt or title tags can already exist and in that case no change is made for them. Anyone for a quick regexp?
  20. Hi Gang, I am trying to create a php function that will parse a html, and alter or <img> tags to add the alt and title attributes that will match the src filename. If you do not know html this is what I am trying to do. <img src="http://www.someserver.com/.../ferrari.jpg"> should be replaced with <img src="http://www.someserver.com/.../ferrari.jpg" alt="ferrari" title="ferrari" > If you understand html you will know what I mean. So function should work like this 1. Accept a string containing html with zero or more <img> tags 2. Extract the name of the image from the src attribute. src can be found in several forms: src="http:/.../image.ext" src = "http:/.../image.ext" src ='http:/.../image.ext' src=http:/.../image.ext 3. Add alt="image" and title="image" (without extension) to the <img> tag 4. Repeat for all images 5. Return altered html (yikes!) I hope someone can help.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.