Jerry L
asked on
PHP Code: Sub-Domain Site Number - Regular Expression Syntax Help Needed
I'm working with a Wordpress Multisite Network (v3.0.4).
I need some help to parse the source code of the wp-admin page at:
"http://www.domain.com/wp-admin/ms-sites.php".
It needs to use "preg_match()" similar to this:
preg_match( "/name=\"_wpnonce_add-blog \" value=\"(.*?)\"/", $this -> page, $match ) ;
$value = $match[1] ;
The expression to be matched is the following:
<a href="http://www.domain.com/wp-admin/ms-sites.php?action=editblog&id=91" class="edit">subdomain91</ a>
But I will use a variable such as the following:
$subDomain = 'subdomain91' ;
Then the expression will contain that variable...
<a href="http://www.domain.com/wp-admin/ms-sites.php?action=editblog&id=91" class="edit">$subDomain</a >
Ultimately, $match[1] must contain '91'
But keep in mind that for another "subdomain" name, the number will be different, id=xx.
I need some help to parse the source code of the wp-admin page at:
"http://www.domain.com/wp-admin/ms-sites.php".
It needs to use "preg_match()" similar to this:
preg_match( "/name=\"_wpnonce_add-blog
$value = $match[1] ;
The expression to be matched is the following:
<a href="http://www.domain.com/wp-admin/ms-sites.php?action=editblog&id=91" class="edit">subdomain91</
But I will use a variable such as the following:
$subDomain = 'subdomain91' ;
Then the expression will contain that variable...
<a href="http://www.domain.com/wp-admin/ms-sites.php?action=editblog&id=91" class="edit">$subDomain</a
Ultimately, $match[1] must contain '91'
But keep in mind that for another "subdomain" name, the number will be different, id=xx.
ASKER
I've attached a larger code snippet (below) that represents the source code of the wp-admin page. (or if you have a wpms blog network, you can look at the "Super Admin > Sites" page for yourself.)
Here is my best shot at the preg_match code. Perhaps you can help me clean it up?
$rootDomain = rootdomain ;
$subDomain = subdomain91 ;
preg_match( "/<a href=\"http:\/\/www\." . $rootDomain . "\/wp-admin/ms-sites\.php\ ?action=ed itblog 8;id=(.*?) \" class=\"edit\">" . $subDomain . "<\/a>/", $this -> page, $matchID ) ;
return "Match ID: " . $matchID[1] ;
However, there's a syntax "Warning" when I run the code...
<< Warning: preg_match(): Unknown modifier '-' in F:\WAMP Server\www\wpModules.php on line 94 >>
I don't know why it doesn't like the minus symbol.
<td class="column-title">
<a href="http://www.rootDomain.com/wp-admin/ms-sites.php?action=editblog&id=91" class="edit">subDomain91</a>
<div class="row-actions">
<span class="edit"><a href="http://www.rootDomain.com/wp-admin/ms-sites.php?action=editblog&id=91">Edit</a></span> | <span class='backend'><a href='http://subDomain91.rootDomain.com/wp-admin/' class='edit'>Backend</a></span> | <span class="activate"><a href="http://www.rootDomain.com/wp-admin/ms-edit.php?action=confirm&action2=deactivateblog&id=91&msg=You+are+about+to+deactivate+the+site+subDomain91">Deactivate</a></span> | <span class="archive"><a href="http://www.rootDomain.com/wp-admin/ms-edit.php?action=confirm&action2=archiveblog&id=91&msg=You+are+about+to+archive+the+site+subDomain91.">Archive</a></span> | <span class="spam"><a href="http://www.rootDomain.com/wp-admin/ms-edit.php?action=confirm&action2=spamblog&id=91&msg=You+are+about+to+mark+the+site+subDomain91+as+spam.">Spam</a></span> | <span class="delete"><a href="http://www.rootDomain.com/wp-admin/ms-edit.php?action=confirm&action2=deleteblog&id=91&msg=You+are+about+to+delete+the+site+subDomain91.">Delete</a></span> | <span class='view'><a href='http://subDomain91.rootDomain.com' rel='permalink'>Visit</a></span> </div>
</td>
Here is my best shot at the preg_match code. Perhaps you can help me clean it up?
$rootDomain = rootdomain ;
$subDomain = subdomain91 ;
preg_match( "/<a href=\"http:\/\/www\." . $rootDomain . "\/wp-admin/ms-sites\.php\
return "Match ID: " . $matchID[1] ;
However, there's a syntax "Warning" when I run the code...
<< Warning: preg_match(): Unknown modifier '-' in F:\WAMP Server\www\wpModules.php on line 94 >>
I don't know why it doesn't like the minus symbol.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
It is very close then.
I need to capture the string here, (.*?), which I thought would be in the $matchID[] array. But when I echo $matchID[0], $matchID[1], and $matchID[2], there seems to be nothing there.
Can you suggest how to accomplish this?
I need to capture the string here, (.*?), which I thought would be in the $matchID[] array. But when I echo $matchID[0], $matchID[1], and $matchID[2], there seems to be nothing there.
Can you suggest how to accomplish this?
ASKER
This (below) is probably more accurate, now that I examined the syntax of preg_match() more carefully. However, it is still not working. Neither print_r shows any content from the $match array.
// Capture the first match
preg_match( "/<a href=\"http:\/\/www\." . $rootDomain . "\/wp-admin\/ms-sites\.php \?action=e ditblog� 38;id=(.*? )\" class=\"edit\">" . $subDomain . "<\/a>/", $this -> page, $matchALL ) ;
print_r( $matchALL[1] ) ;
// Now, isolate the important part
preg_match( "/id=(.*?)/", $matchALL[1], $matchID ) ;
print_r( $matchID[1] ) ;
// Capture the first match
preg_match( "/<a href=\"http:\/\/www\." . $rootDomain . "\/wp-admin\/ms-sites\.php
print_r( $matchALL[1] ) ;
// Now, isolate the important part
preg_match( "/id=(.*?)/", $matchALL[1], $matchID ) ;
print_r( $matchID[1] ) ;
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks, kaufmed, for your assistance.
Open in new window