Jump to content

AudiS2

Members
  • Posts

    22
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

AudiS2's Achievements

Newbie

Newbie (1/5)

1

Reputation

  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!
×
×
  • 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.