help with preg_match

Started on the old forum in August 2012 · view the original in the archive · old links redirect here

6 replies · 471 views · started 14 years ago · 1 min read

3 participants
razor Developer · 52 posts #1

i want to split an total url like it is in format :

<a href='http://red.domain.net/ck.php?id=o2SjLKWuoKZ9Uy9sLzShozIlnJD9ZGNkZwRlK196o25ynJD9ZwtlAy9sL2V9ZmyvZmSxAmEzAz'>test test test etc..</a>

i want to split it and just want to get http://red.domain.net/ck.php?id=o2SjLKWuoKZ9Uy9sLzShozIlnJD9ZGNkZwRlK196o25ynJD9ZwtlAy9sL2V9ZmyvZmSxAmEzAz what will be this ? i tried like:

$data = "<a href='http://red.domain.net/ck.php?id=o2SjLKWuoKZ9Uy9sLzShozIlnJD9ZGNkZwRlK196o25ynJD9ZwtlAy9sL2V9ZmyvZmSxAmEzAz'>test test test etc..</a>";
preg_match('@href="(.+?)"@is',$data,$match);
$get = $match[1];

but not successful, can any one help?

razor Developer · 52 posts #3

not clear yet

softwarefreak Senior · 349 posts #4

razor wrote: not clear yet

hmm, try ds

<?php
$data = "<a href='http://red.domain.net/ck.php?id=o2SjLKWuoKZ9Uy9sLzShozIlnJD9ZGNkZwRlK196o25ynJD9ZwtlAy9sL2V9ZmyvZmSxAmEzAz'>test test test etc..</a>"; 
preg_match('@<a href=[\'|"](.+)[\'|"]>@is',$data,$match); 
print_r($match);

I need some facebook likes, can you please help me 🤝 http://facebook.com/softwarefreakin I noticed social media is really powerful 🧙 Well DONE is better than well SAID

razor Developer · 52 posts #5

softwarefreak wrote: hmm, try ds

<?php
$data = "<a href='http://red.domain.net/ck.php?id=o2SjLKWuoKZ9Uy9sLzShozIlnJD9ZGNkZwRlK196o25ynJD9ZwtlAy9sL2V9ZmyvZmSxAmEzAz'>test test test etc..</a>"; 
preg_match('@<a href=[\'|"](.+)[\'|"]>@is',$data,$match); 
print_r($match);

that should be $match[1] ... thanks dude for the help...

softwarefreak Senior · 349 posts #6

razor wrote: that should be $match[1] ... thanks dude for the help...

print_r() is the best way to work with arrays, welcome anyways

Added after 10 minutes:

BTW, here's the code to match all the anchor links from a page

<?
$data = file_get_contents("http://youtube.com"); 
preg_match_all('@<a href=[\'|"](.+)[\'|"]@Uis',$data,$match);
$links = $match[1]; 
$count = count($links);
for ($i=0; $i < $count; $i++) 
{ 
	echo $links[$i] . "<br />\n";
}

I need some facebook likes, can you please help me 🤝 http://facebook.com/softwarefreakin I noticed social media is really powerful 🧙 Well DONE is better than well SAID

nimeshka Developer · 180 posts #7

explode();

This is very easy,

$data = "<a href='http://red.domain.net/ck.php?id=o2SjLKWuoKZ9Uy9sLzShozIlnJD9ZGNkZwRlK196o25ynJD9ZwtlAy9sL2V9ZmyvZmSxAmEzAz'>test test test etc..</a>"; 

$var = explode("'", $data);

echo $var[1];

this will output what you exactly need...........

External image (may be gone)

I'm Proud to be a Sri Lankan!

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close