Jump to content

Search the Community

Showing results for tags 'preg_match_all'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Welcome to PHP Freaks
    • Announcements
    • Introductions
  • PHP Coding
    • PHP Coding Help
    • Regex Help
    • Third Party Scripts
    • FAQ/Code Snippet Repository
  • SQL / Database
    • MySQL Help
    • PostgreSQL
    • Microsoft SQL - MSSQL
    • Other RDBMS and SQL dialects
  • Client Side
    • HTML Help
    • CSS Help
    • Javascript Help
    • Other
  • Applications and Frameworks
    • Applications
    • Frameworks
    • Other Libraries
  • Web Server Administration
    • PHP Installation and Configuration
    • Linux
    • Apache HTTP Server
    • Microsoft IIS
    • Other Web Server Software
  • Other
    • Application Design
    • Other Programming Languages
    • Editor Help (PhpStorm, VS Code, etc)
    • Website Critique
    • Beta Test Your Stuff!
  • Freelance, Contracts, Employment, etc.
    • Services Offered
    • Job Offerings
  • General Discussion
    • PHPFreaks.com Website Feedback
    • Miscellaneous

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests


Age


Donation Link

Found 9 results

  1. hello every body, Currently i'm scraping web data for a demo project but i cant preg_match the value from this html. The html code is <div class="carouselContainer leftDisabled"> <ul class="carousel leftDisabled"> <li> <div class="thumbContainer"> <div class="thumb" style="background-image:url(http://img6a.flixcart.com/image/mobile/v/h/g/samsung-galaxy-core-2-sm-g355h-100x100-imadzb4ywyj25mw4.jpeg)" data-imageId="IMADZB4YWYJ25MW4"> </div> </div> </li> <li> <div class="thumbContainer"> <div class="thumb" style="background-image:url(http://img6a.flixcart.com/image/mobile/v/h/g/samsung-galaxy-core-2-sm-g355h-100x100-imadzb4zhk4855ny.jpeg)" data-imageId="IMADZB4ZHK4855NY"> </div> </div> </li> <li> <div class="thumbContainer"> <div class="thumb" style="background-image:url(http://img6a.flixcart.com/image/mobile/v/h/g/samsung-galaxy-core-2-sm-g355h-100x100-imadzwrpmdwhnxg7.jpeg)" data-imageId="IMADZWRPMDWHNXG7"> </div> </div> </li> <li> <div class="thumbContainer"> <div class="thumb" style="background-image:url(http://img6a.flixcart.com/image/mobile/v/h/g/samsung-galaxy-core-2-sm-g355h-100x100-imadzwvvz3deeh4c.jpeg)" data-imageId="IMADZWVVZ3DEEH4C"> </div> </div> </li> </ul> </div> The regex i've used is preg_match_all('|<div class="carouselContainer leftDisabled"+>(.*)</div+>|U',$txt,$matches3); I want only the images images url from that specific block. Can anybody help me in this plz...
  2. I have a group of letter that consists letters like $words= 'estroaroint'; that can be arranged to be some words in my list $file = 'dictionary.txt' Here my expected result that on my words list: STORE REST TRAIN RESTORATION ...etc I searched on google and found like : $contents = file_get_contents($file); $pattern = preg_quote($words, '/'); $pattern = "/^.*$pattern.*\$/m"; if(preg_match_all($pattern, $contents, $matches)){ echo "Found matches:\n"; echo implode("\n", $matches[0]); echo strlen($matches); } else{ echo "No matches found"; } But that's not like as my expectation Thanks in advance Warm Regard
  3. Hi, I'm using TCPDF to create a PDF from a webpage. This works great but I have the following problem: I'm building in WordPress and as you may know WP saves images on different sizes. (e.g. 150x150, 300x300 and 1024x1024) The thing I'm trying to create is that users can download a PDF ready for printing. So High Resolution images. I use a preg_match_all function to match the image source and remove the additional image size from the filename so the original high resolution image is loaded. e.g. image-150x150.jpg will be replaced by image.jpg. So now the original image that has a image size of 6024x6024px and 300 DPI is loaded. Then TCPDF uses a resize function that resizes the image back to 150x150 px but sets the DPI to 300 so it can be printed on a good quality. This all works but now the problem comes: If I do the preg_match_all function the image gets "pulled" from the rest of the content and looses it's position. So my thought to fix this was. Get a preg_replace function and replace the image tag with a function that executes the whole image change like described above. This doesn't work...... So i'm stuck here. Hope anyone can assist me with this. Here is what I have done so far. function execute(){ preg_match_all("/<img[^>]+src=(?:\"|\')\K(.[^\">]+?)(?=\"|\')/",$content,$matches,PREG_PATTERN_ORDER); for( $i=0; isset($matches[1]) && $i < count($matches[1]); $i++ ) { $search = array('-'.$s1.'x'.$s2.'', '-'.$s3.'x'.$s4.'', '-'.$s5.'x'.$s6.''); $replace = array('', '', ''); $a = $matches[1][$i]; if (strpos($a,'-'.$s1.'x'.$s2.'') !== false) { $w = $s1; $w = $pdf->pixelsToUnits($w); $h = $s2; $h = $pdf->pixelsToUnits($h); $l = '57'; $l = $pdf->pixelsToUnits($l); $t = '170'; $t = $pdf->pixelsToUnits($t); }elseif (strpos($a,'-'.$s3.'x'.$s4.'') !== false) { $w = $s3; $w = $pdf->pixelsToUnits($w); $h = $s4; $h = $pdf->pixelsToUnits($h); $l = '217'; $l = $pdf->pixelsToUnits($l); $t = '20'; $t = $pdf->pixelsToUnits($t); }elseif (strpos($a,'-'.$s5.'x'.$s6.'') !== false) { $w = $s5; $w = $pdf->pixelsToUnits($w); $h = $s6; $h = $pdf->pixelsToUnits($h); $l = '57'; $l = $pdf->pixelsToUnits($l); $t = '310'; $t = $pdf->pixelsToUnits($t); } $content .= $pdf->Image(str_replace($search,$replace,$matches[1][$i]), $l, $t, $w, $h, 'JPG', '', '', true, 300, '', false, false, 0, false, false, false); } }; global $post; $id = $_GET['id']; $content_post = get_post($id);// get the content $content = $content_post->post_content; $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); $content = preg_replace('/<img[^>]+./e',execute(), $content); // replace the image tag with the new image // EXPORT IT ALL $pdf->writeHTML($content, true, false, true, false, '');
  4. I need to match n occurrences of "." in a string following specific rules. The number of occurrences found by the regex should correspond with the exact amount of "."'s in the string. The rules are: 1) every "." must be preceded by at least one digit from 1-9, and can be preceded by up to two other digits from 0-9 (basically, values from 1-999) 2) every "." must be followed by at least one digit from 1-9, and can be followed by up to two other digits from 0-9 (again, values from 1-999). Sample valid strings are: 1) "1.3.5.7.9" 2) "21.23.25.27.29" Sample invalid strings are: 1)"01.5.7.9" (first digit of the number preceding the dot cannot be a zero) 2) "1.05.7.9" (first digit of the number preceding or following the dot cannot be a zero) 3) "1.5.7777.9999" (cannot have more than 1 digit with value 1-9 and up to two more digits with value 0-9 (so up to 3 digit numbers); here we have four digit numbers) I'm using preg_match_all to match all occurrences of the dot in the string, and I'm using lookaheads seeing that the digits matched are shared between the dots (the same digit that is preceding a dot is following another dot). The problem is, when I have two or three digit numbers, I'm getting more matches than I need. Here is my pattern: /(?=([1-9][0-9]{0,2}\.[1-9][0-9]{0,2}))/ Here is my test subject: "Mt1,1-15.17.19" There are only two dots, but I am getting four matches: array ( 0 => array ( 0 => '', 1 => '', 2 => '', 3 => '', ), 1 => array ( 0 => '15.17', 1 => '5.17', 2 => '17.19', 3 => '7.19', ), ) I would like to get only two matches ('15.17' and '17.19'), as many matches as there are dots that fall within the rules but no more. <?php $string = "Mt1,15.17.19"; if(preg_match_all("/(?=([1-9][0-9]{0,2}\.[1-9][0-9]{0,2}))/",$string ) != substr_count($string ,".") ){ echo "There are ".substr_count($string ,".")." dots in this string, but there are ".preg_match_all("/(?=([1-9][0-9]{0,2}\.[1-9][0-9]{0,2}))/",$string )." valid occurrences of the dot!"; } ?> Since there can't logically be more valid occurrences than actual occurrences, for the time being I'm just using a "less than" operator instead of a "not equals" operator. But I would like to learn how to get a regex pattern that matches the exact amount of valid instances.
  5. I am trying to extract the strings that match this pattern @xyz from an input string using the preg_match_all() php function. My results are to be outputted to $match, as an array where $match[0] should contain all full matches. But what I am getting is an empty array. I would appreciate a clue to resolve this. My code is below. <?php $data = "@mike The party will start at 10:30 pm and @John run untill 12:30 am. Please @Emeka, could you inform @Joseph?"; preg_match_all('/^@(a-z)*$/', $data, $match, PREG_PATTERN_ORDER); echo "Matches: <br>"; print_r($match[0]); ?> Thanks.
  6. I have problem creating patern with preg_match_all and add it to array, its involved json data, Ch0cu3r helped me alot with my previous question http://forums.phpfreaks.com/topic/285059-preg-match-all-problem/, maybe he is still around? VI.data.aurora.idx = {140108: {act: 3, sun: ['s0','16:00','11:08','17:12','09:56'], moon: ['7','t3','03:51','']}, 140109: {act: 2, sun: ['s0','16:02','11:06','17:14','09:55'], moon: ['8','t3','05:12','']}, 140110: {act: 2, sun: ['s0','16:05','11:04','17:16','09:54'], moon: ['9','t3','06:28','']}, 140111: {act: 3, sun: ['s0','16:08','11:02','17:18','09:52'], moon: ['10','t3','07:35','']}, 140112: {act: 2, sun: ['s0','16:11','11:00','17:20','09:51'], moon: ['11','t3','08:30','']}, 140113: {act: 2, sun: ['s0','16:14','10:57','17:23','09:49'], moon: ['12','t3','09:11','']}, 140114: {act: 2, sun: ['s0','16:17','10:55','17:25','09:48'], moon: ['13','t3','09:41','']}, 140115: {act: 2, sun: ['s0','16:20','10:53','17:27','09:46'], moon: ['14','t4','16:33','10:03']}, 140116: {act: 2, sun: ['s0','16:23','10:50','17:30','09:44'], moon: ['15','t4','17:46','10:18']}, 140117: {act: 2, sun: ['s0','16:26','10:48','17:32','09:42'], moon: ['16','t4','19:03','10:30']}}
  7. I have the following string : 't':new Date(2014,1-1,3,9,35,38),'a':'3.57289','lat':'12,123','lon':'-12,123','dep':'1,1','s':'1,0','q':'90,02','dL':'4,3','dD':'VSV','dR':'PlaceName' t=date and time a=? lat=latitude lon=longitude dep=depth s=magnitude q=quality dL=? dD=direction dR=PlaceName I am trying to get the data into array with preg_match_all Can anyone help me out?
  8. I am trying to match only the word "handle" in this Tweet: @testing50037393 @handle 123456 #checkin I am using this regex expression - (?!testing50037393|checkin|\b\d)(\b\w+) I am getting two results of the string "handle" as an array instead of just "handle" once. Please tell me how I can stucture this query to just get one instance of "handle". I am getting this result with preg_match - Array ( [0] => handle [1] => handle ) And this with preg_match_all - Array ( [0] => Array ( [0] => handle ) [1] => Array ( [0] => handle ) ) Thanks, Lela
  9. This is the first part of the search script and i was doing some debuging and i cant figure out why this code if( !($fd = fopen($url,"r")) ){ die( "Could not open URL!" ); } while( $buf = fgets($fd,1024) ) { /* Remove whitespace from beginning and end of string: */ $buf = trim($buf); /* Try to remove all HTML-tags: */ $buf = strip_tags($buf); $buf = preg_replace('/&\w;/', '', $buf); /* Extract all words matching the regexp from the current line: */ preg_match_all("/(\b[\w+]+\b)/",$buf,$words); print_r($words); } doubles each associate array like this Array ( [0] => Array ( ) [1] => Array ( ) ) Array ( [0] => Array ( [0] => It [1] = > was [2] => November ) [1] => Array ( [0] => It [1] = > was [2] => November ) ) When I would expect this Array ( [0] => Array ( ) ) Array ( [0] => Array ( [0] => It [1] = > was [2] => November ) )
×
×
  • 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.