/    Sign up×
Community /Pin to ProfileBookmark

RegExp in between the .’s

Hello,

I’ve been racking my brain with regular expressions and writing patterns. What I’ve been trying to do is giving me a brain squeeze. Maybe some one could help.

I’m getting the refering site with

[code=php]$thisPage=$_SERVER[PHP_SELF];
[/code]

and I just want to get the domain. Everything in between the first . and the second dot. This is where I eventually gave when writing the pattern

[code=php]$pattern = “/.{*}./”;
[/code]

Thanks,
maddDidley
[url]www.maddapps.com[/url]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@NogDogSep 20.2006 — Hello,

I've been racking my brain with regular expressions and writing patterns. What I've been trying to do is giving me a brain squeeze. Maybe some one could help.

I'm getting the refering site with
[code=php]$thisPage=$_SERVER[PHP_SELF];

[/code]

[/quote]

Are you sure you don't mean $_SERVER['HTTP_REFERRER']?

and I just want to get the domain. Everything in between the first . and the second dot. This is where I eventually gave when writing the pattern

[code=php]$pattern = "/.{*}./";
[/code]


Thanks,

maddDidley

www.maddapps.com[/QUOTE]

Remember that '.' means "any character" in a regex, so you'll have to escape it if you want a literal period (or put it in a character class within square bracets).

Anyway, can you show me an explicit before and after example, showing what the input would look like and what precise value you want to end up from that source string? That way we can provide an exact solution rather than guessing what's needed.
Copy linkTweet thisAlerts:
@madddidleyauthorSep 20.2006 — ah yes, I'm trying to make a stats app and I don't want to include any refering links from its my own site. like going back to the home page from a different page on that site. this is the code I'm using

[code=php]
$thisPage=$_SERVER[PHP_SELF];

$pattern = "/.{*}./";
$domain = preg_match($pattern, $thisPage); // = "maddapps";
echo "<B>Top References</B><BR>Number of Hits - - Referred From<BR>";
$result = mysql_query("SELECT COUNT(refer) AS CNT, refer FROM $dbsql WHERE refer NOT LIKE '%$domain%' AND ip != '$myip' GROUP BY refer ORDER
BY CNT DESC LIMIT 10");


while ($row = mysql_fetch_array($result)) {


echo $row["CNT"];
echo " - - - - ";
echo $row["refer"];
echo "<BR>";

}
[/code]
Copy linkTweet thisAlerts:
@NogDogSep 20.2006 — How about:
[code=php]
$domain = array_shift(explode('.', $_SERVER['SERVER_NAME']));
[/code]
Copy linkTweet thisAlerts:
@madddidleyauthorSep 20.2006 — Thanks, for that. I wasn't sure how to go about getting the domain. That helps.
×

Success!

Help @madddidley spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...