|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* SEOstats Example - Get SEMrush Metrics as Graphs |
|
4
|
|
|
* |
|
5
|
|
|
* @package SEOstats |
|
6
|
|
|
* @author Stephan Schmitz <[email protected]> |
|
7
|
|
|
* @copyright Copyright (c) 2010 - present Stephan Schmitz |
|
8
|
|
|
* @license http://eyecatchup.mit-license.org/ MIT License |
|
9
|
|
|
* @updated 2014/07/26 |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
// NOTE: The given path to the autoload.php assumes that you installed SEOstats via composer |
|
13
|
|
|
// and copied this example file from ./vendor/seostats/seostats/example/example.php to ./example.php |
|
14
|
|
|
// |
|
15
|
|
|
// If you did NOT installed SEOstats via composer but instead downloaded the zip file from github.com, |
|
16
|
|
|
// you need to follow this steps: |
|
17
|
|
|
// |
|
18
|
|
|
// 1. Comment-in line 24 (remove hash char "#") and comment-out line 25 (prepend hash char "#") |
|
19
|
|
|
// 2. Copy this example file (and the others) from ./example/example.php to ./example.php |
|
20
|
|
|
// |
|
21
|
|
|
// For further reference see: https://github.com/eyecatchup/SEOstats/issues/49 |
|
22
|
|
|
|
|
23
|
|
|
// Bootstrap the library / register autoloader |
|
24
|
|
|
#require_once realpath(__DIR__ . '/SEOstats/bootstrap.php'); |
|
25
|
|
|
require_once realpath(__DIR__ . '/vendor/autoload.php'); |
|
26
|
|
|
|
|
27
|
|
|
use \SEOstats\Services\SemRush; |
|
28
|
|
|
|
|
29
|
|
|
try { |
|
30
|
|
|
$url = 'http://www.google.de/'; |
|
31
|
|
|
|
|
32
|
|
|
// Create a new SEOstats instance. |
|
33
|
|
|
$seostats = new \SEOstats\SEOstats; |
|
34
|
|
|
|
|
35
|
|
|
// Bind the URL to the current SEOstats instance. |
|
36
|
|
|
if ($seostats->setUrl($url)) { |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Print HTML code for the 'search engine traffic'-graph. |
|
40
|
|
|
*/ |
|
41
|
|
|
echo SemRush::getDomainGraph(1); |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Print HTML code for the 'search engine traffic price'-graph. |
|
45
|
|
|
*/ |
|
46
|
|
|
echo SemRush::getDomainGraph(2); |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Print HTML code for the 'number of adwords ads'-graph, |
|
50
|
|
|
* using explicitly SEMRush's data for google.de (german index). |
|
51
|
|
|
*/ |
|
52
|
|
|
echo SemRush::getDomainGraph(3, false, 'de'); |
|
|
|
|
|
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Print HTML code for the 'adwords traffic'-graph, using |
|
56
|
|
|
* explicitly SEMRush's data for google.de (german index) |
|
57
|
|
|
* and specific graph dimensions of 320*240 px. |
|
58
|
|
|
*/ |
|
59
|
|
|
echo SemRush::getDomainGraph(4, false, 'de', 320, 240); |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
/** |
|
62
|
|
|
* Print HTML code for the 'adwords traffic price'-graph, |
|
63
|
|
|
* using explicitly SEMRush's data for google.de (german index), |
|
64
|
|
|
* specific graph dimensions of 320*240 px and specific |
|
65
|
|
|
* graph colors (black lines and red dots for data points). |
|
66
|
|
|
*/ |
|
67
|
|
|
echo SemRush::getDomainGraph(5, false, 'de', 320, 240, '000000', 'ff0000'); |
|
|
|
|
|
|
68
|
|
|
} |
|
69
|
|
|
} |
|
70
|
|
|
catch (\Exception $e) { |
|
71
|
|
|
echo 'Caught SEOstatsException: ' . $e->getMessage(); |
|
72
|
|
|
} |
|
73
|
|
|
|
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: