Hello,

I tried to use regex to search through

blablablablahttp://www.myspace.com/username

by using

preg_match('~http://www\.myspace\.com/.+"~',$string,$match);

The tilde or lack of was tripping me up... am I even close?
I was just trying to extract the username at the end, before it was marked off by a double quote ("). I tried adapting this answer from a previous forum post but it doesn't seem to be working. Any help would be appreciated.

Thanks,

L

Recommended Answers

All 5 Replies

Well if you're trying to extract the username you can just do this.

$url = 'http://www.myspace.com/username';
$urlparts = explode('/', $url);
$username = end($urlparts);

Thanks so much, I'll test it out and see if I can get it working, I should be able to.

I don't know how to tie it in to

else {

	$timeout = 300;

	ini_set('max_execution_time','120');

	set_time_limit(120);

	ini_set('default_socket_timeout','120');

	while($contents = fread($handle,'1024'))

	{ $hold .= $contents; }

above it. Could anyone tell me what function the ~ serves? I don't see it in any regex guides.

The tilde has no special meaning, it was just chosen as the delimiter so the slashes didn't have to be escaped. You can choose pretty much any delimiter.

$regex1 = '/http:\/\/www\.example.com\/blah/';
// vs
$regex2 = "#http://www\.example\.com/blah#';

I prefer to use / and # but it looks like the tilde was their choice.

preg_match('~http://www\.myspace\.com/(.*)"~',$hold,$match);

This worked for me but thanks for the info on the tildes... regex isn't that bad with a running start.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.