Jump to content

aCa

Members
  • Posts

    12
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

aCa's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. There is lot information about regex out there. Many easier places then php.net to learn php. Just do a google search for regex php tutorial or somthing. Ok, so now over to your question. If it is allways indi + number you are looking for then a code like this should solve it. preg_match('/indi[0-9]+/i', 'http://www.mysite.co.uk/tc_test/_resources/signals/s60-3/indi2/sig2.png', $result); You can test it at my regex tester at http://regex.larsolavtorvik.com. Hope this helps!
  2. Could you provide us with some more info? Is your example the text you will check and only want the numbers? If that is the case somthing like this might solve your problem: preg_match_all('/([0-9]+)°\s([0-9]+)'/', $string, $result);
  3. Hmm I tryed you preg_replace in my regex test tool and for me the test'ing worked fine... But as effigy said. Since you are accepting ' then you need to do mysql_real_escape_string before you post to database becouse the ' will break the SQL.
  4. Hi Would this regex solve your problem? \[embed_viewat(( width=[0-9]+)|( height=[0-9]+)|( id=[0-9]+)|( lang=[a-z]+))+\] It doesn't give you exactly the array like you wanted but it gives you the values you need. Will f.eks return: Array ( [0] => Array ( [0] => [embed_viewat height=400 width=600 lang=de id=1234] ) [1] => Array ( [0] => id=1234 ) [2] => Array ( [0] => width=600 ) [3] => Array ( [0] => height=400 ) [4] => Array ( [0] => id=1234 ) [5] => Array ( [0] => lang=de ) )
  5. You could use somthing like this: preg_replace('/(<img[^>]+>)/i', '<a href="/url/to/page">$1</a>', '<img id="ff_header" src="/files/imce_images/image_file.jpg" height="400" width="400" />');
  6. Hmm I'm sorry. I don't know what you are trying to do anymore. The code you get when you do a var_dump is the actual price... wasn't it the price you wanted to retrieve? Just use the variabel $match[1], it should allways contain the price. Then you can print it, echo it, store it in xml, store it in datbase... in other words do whatever you wan't with it :-) If it is not the price you are after, could you please try and explain again what you need?
  7. Hmm took a look at you code. Wont you get the additional span class data etc also included in your result? if (preg_match('/<span>(.*?)<\/span><span.*?>(.*?)<\/span>/i', '<span>Welcome </span><span class="blu10" style="font-weight:bold;">name1 name</span>', $result)) { echo $result[1].$result[2]; } Wouldn't this give you the result you requested? You have probably figured out your other problem and one of many ways to get the time is with a pattern like this: $pattern = '<span>(?=\d)(.*?)<\/span>';
  8. If you don't wan't the to check for $ then modify discomatt regex like this: $regex = '%<span class="text-breaker">\s++<b>Sale price:</b> ([\d]++)\s++</span>%';
  9. Somthing like this will probably work better: preg_match_all('/[a-z\s-]+/i', $string, $result); It will match strings with the chars you said. You used [^ that means NOT match the chars you selected. You also used a . and that is the wildcard char. I used match all to get all matches instead of only the first match. What is correct for you depend on what you will use it for. If it is going to be used as input name validation somthing like this is probably better. preg_match('/^[a-z\s-]+$/i', $string, $result); This will also make sure that it is the whole string since ^at the front indicates a start and $ indicates the end. Try and test your pattern and my pattern on my regex tool and see how the act differently. Regex is fun as soon as you learn more about it :-)
  10. A small coment. I agree that the pattern /[\W]+/ is the best to use. But we need one more regex. You stated you didn't wan't _ at the end of words. You will need to do a replace with a pattern like this: /_(\s)|_$/ That will remove _ when space or end of line after it.
  11. To only match the values with whitespace on each side you could use this pattern: /\s_(.+)_\s/iU Would that solve your problem? I have a beta out of my regex tool that can help you test the expression to make sure it is exactly what you wan't, http://regex.larsolavtorvik.com/.
×
×
  • 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.