473,396 Members | 2,010 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to fix preg_match Compilation failed: error?

i am trying to get preg_match to find links that end in .mp3.
the call i am using is
Expand|Select|Wrap|Line Numbers
  1. preg_match('/*.mp3/',$url,$matches);
  2.  
and i am getting the error

Warning: preg_match() [function.preg-match]: Compilation failed: nothing to repeat at offset 0
Feb 25 '11 #1
4 5116
i fixed that problem i think by doing
Expand|Select|Wrap|Line Numbers
  1. preg_match('/.*mp3/',$url,$matches);
  2.  
i am not getting any results now.

this is what it looks like now
Expand|Select|Wrap|Line Numbers
  1. $dom = new DOMDocument();
  2. @$dom->loadHTML($html);
  3. $xpath = new DOMXPath($dom);
  4. $hrefs = $xpath->evaluate("/html/body//a");
  5.  
  6. for($i = 0; $i < $hrefs->length; $i++)
  7. {
  8.     $href = $hrefs->item($i);
  9.     $url = $href->getAttribute('href');
  10.     preg_match('/.*mp3/',$url,$matches);
  11. }
  12. echo $matches;
  13.  
Feb 25 '11 #2
dlite922
1,584 Expert 1GB
First print matches like an array using print_r(). Echo does not print arrays.

Second, your echo will only print the last things that was in matches. If you want to print every URL, put your echo/print statement inside the for loop.

Dan
Feb 25 '11 #3
but will the preg_match statement properly get every url that ends in .mp3?
Feb 25 '11 #4
it does work i was trying to access the $matches array out of scope.
Feb 25 '11 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: fartsniff | last post by:
hello all, here is a preg_match routine that i am using. basically, $image is set in some code above, and it can be either st-1.gif or sb-1.gif (actually it randomly picks them from about 100...
10
by: aaron | last post by:
I need some help with validating an email address. Right now, I am doing this: function sys_is_valid_email ($s) { if (preg_match ("/^.+@.+\..+$/", $s)) { return 1; } else { return 0; } }
2
by: tgh003 | last post by:
I need help with a regex. Been at it for hours and need some sanity help :> I am using preg_match in PHP to strip a IMG html tag. I want to strip any IMG tag that has /work/doc?g= in the SRC...
0
by: awebguynow | last post by:
I ran across this code, and it kind of made me nervous: (as an email validator) if ( !preg_match("/.*\@.*\..*/", $_POST) | preg_match("/(\)/", $_POST) ) 1) from bitwise experience with "C",...
2
by: David | last post by:
Help how can I force the variable to start with a character. I dont want it to start with a number???? function alphanumeric($alphanumeric_field) {...
3
by: Happy Face | last post by:
Hi, All, I encountered this strange problem while using function preg_match. The following is the php code. when I set the line: $text = str_repeat('*', 12500); preg_match will return 0 for...
8
by: Thomas Mlynarczyk | last post by:
Hello, I want to split a given string into tokens which are defined by regexes: // example tokens - a bit more complex in real $tokens = array( 'NUMBER' ='~^\d+~', 'NAME' ='~^+~', 'ANY' ...
5
by: jeddiki | last post by:
Hi, I am wanting to do a simple extraction of the three key header elements from a web page namely these: Is the preg_match() function the best way to find them and put them into variables...
3
by: wizardry | last post by:
hello - i need to convert this string to preg_match to support current version of php. i have googled and found some info but still get an error where it doesnt like my search string. if...
1
oranoos3000
by: oranoos3000 | last post by:
hi i read below text and i understand what say but i dont identify meaning of this setence preg_match may not fail on 4 and 5 octet sequences, even though they are not supported by the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.