-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathindex.html
369 lines (334 loc) · 13.2 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<link rel="canonical" href="https://caniphp.com/" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta
name="og:title"
content="Can I PHP? - caniuse.com but for PHP features"
/>
<meta name="og:description" content="caniuse.com but for PHP features" />
<meta
name="og:image"
content="https://can-i-use.com/images/can-i-php-screen.png"
/>
<title>Can I PHP? - caniuse.com but for PHP features</title>
<meta
name="description"
content="A list of PHP features and the versions of PHP that they are present in. Like caniuse.com but for PHP!"
/>
<link href="/dist/style.css" rel="stylesheet" />
</head>
<body>
<div
id="app"
x-data="caniphp"
class="text-center pt-6 pb-24 px-6 md:w-2/3 max-w-4xl mx-auto"
>
<header class="mb-12 relative">
<div class="mb-14 text-sm">
<a
class="underline hover:no-underline"
href="https://github.com/rosswintle/can-i-php/blob/main/README.md"
>README.md</a
>
—
<a
class="underline hover:no-underline"
href="https://github.com/rosswintle/can-i-php"
>GitHub</a
>
— By
<a
class="underline hover:no-underline"
href="https://rw.omg.lol/"
>Ross Wintle</a
>
—
<a
class="underline hover:no-underline"
href="https://ko-fi.com/magicroundabout"
>Buy me coffee</a
>
OR
<a class="underline hover:no-underline" href="https://turbo-admin.com"
>Check out my WordPress Browser Extension</a
>
</div>
<div class="mb-4 text-2xl">
<strong>Unofficial</strong> and <em>incomplete</em>
</div>
<h1 class="text-6xl tracking-wider font-bold mb-3">Can I PHP?</h1>
<p class="text-center mx-auto lg:w-2/3">
PHP feature support by version - like caniuse.com but for PHP.<br />
This is a list of language features and functions added or removed in
recent PHP versions. It is not an exhaustive reference.
</p>
<div class="w-auto px-6 py-4 bg-red-500 text-white font-bold absolute left-auto right-5 top-8 rotate-6">
Now with added PHP 8.4!
</div>
</header>
<main>
<form action="" @submit.prevent="">
<input
x-model="searchString"
type="search"
name="s"
placeholder="Search for a PHP feature"
class="w-full md:w-2/3 mb-6 md:mb-8 text-xl md:text-3xl py-4 px-6 border-2 rounded-md"
/>
</form>
<p class="mb-2">
Or view what's changed in a PHP version:
</p>
<ul class="flex flex-wrap w-full justify-center mb-12">
<li>
<button @click="versionFilter=''" class="leading-none mb-4 px-4 py-2 rounded-md transition" :class="versionFilter === '' ? 'bg-blue-300' : 'bg-gray-200'">All</button>
</li>
<template x-for="version in versions">
<li>
<button x-text="version.version" @click="versionFilter=version.version" class="leading-none mb-4 px-4 py-2 rounded-md transition ml-4" :class="versionFilter === version.version ? 'bg-blue-300' : 'bg-gray-200'"></button>
</li>
</template>
</ul>
<div
class="text-left prose lg:prose-xl"
x-show="filteredFeatures().length === 0 && !loading"
style="display: none"
>
<h3>Nothing matches!</h3>
<p>It could be that:</p>
<ul>
<li>
We know about the thing, but your search didn't find it - try
again! If you think search didn't work for a given feature, please
raise an issue or PR on
<a href="https://github.com/rosswintle/can-i-php">
the GitHub repo</a
>
to improve the keywords.
</li>
<li>
The feature was not added in, deprecated from or removed from a
recent PHP version. caniphp.com is not a list of ALL PHP functions
and features, just those added or removed in recent versions.
</li>
<li>
We don't know about the thing yet. The information here is being
manually curated, and is not yet complete. So please bear with us
as we add more data, or contribute what you were looking for on
<a href="https://github.com/rosswintle/can-i-php">GitHub.</a>
</li>
</ul>
<p>
If you think something is missing then feel free to open a pull
request on
<a href="https://github.com/rosswintle/can-i-php"
>the GitHub repo</a
>
to add it.
</p>
</div>
<div class="text-left">
<template x-for="feature in filteredFeatures()">
<!-- Feature panel -->
<article class="w-full mb-6">
<!-- Feature info -->
<div class="w-full border border-b-none py-2 px-4">
<h2 x-text="feature.name" class="text-lg mb-4 font-bold"></h2>
<div class="flex">
<!-- Feature top panel, left column -->
<div class="w-3/4 pr-4">
<p
x-html="formatAsHtml(feature.description)"
class="mb-6"
></p>
<h3 class="font-bold text-l mb-2">Resources</h3>
<ul
x-show="feature?.resources?.length > 0"
class="list-disc list-inside text-sm mb-4"
>
<template x-for="resource in feature.resources">
<li>
<a
x-text="resource.name"
class="underline hover:no-underline"
:href="resource.url"
></a>
</li>
</template>
</ul>
</div>
<div class="w-1/4 pl-4">
<p x-show="feature.added && feature.added !== '0.0'">
Added: PHP v<span x-text="feature.added"></span>
</p>
<p x-show="feature.deprecated">
Deprecated: PHP v<span x-text="feature.deprecated"></span>
</p>
<p x-show="feature.removed">
Removed: PHP v<span x-text="feature.removed"></span>
</p>
</div>
</div>
</div>
<!-- Feature versions - colored boxes -->
<div class="flex w-full overflow-auto">
<template x-for="version in versions">
<div
class="flex-1 px-3 py-2 text-center"
:class="featureSupportedClass(feature, version.version)"
>
<span x-text="version.version"></span>
</div>
</template>
</div>
</article>
</template>
</div>
</main>
</div>
<!-- Fathom - beautiful, simple website analytics -->
<script src="https://cdn.usefathom.com/script.js" data-site="IULNCQBS" defer></script> <!-- / Fathom -->
<script src="versions.js"></script>
<script src="//unpkg.com/alpinejs" defer></script>
<script>
document.addEventListener("alpine:init", () => {
document.querySelector("input[name=s]").focus();
const url = new URL(window.location.href);
const searchParam = url.searchParams.get("s");
const versionFilter = url.searchParams.get("version");
Alpine.data("caniphp", () => {
return {
// searchString: window.location.pathname.slice(1) ?? '',
searchString: searchParam ?? "",
features: [],
loading: true,
versions: versions,
versionFilter: versionFilter ?? "",
async init() {
const featuresData = await fetch("/features.json");
this.features = await featuresData.json();
this.loading = false;
this.$watch("searchString", (value) => {
const url = new URL(window.location.href);
if (value.length > 0) {
url.searchParams.set("s", value);
} else {
url.searchParams.delete("s");
}
history.replaceState(null, "", url);
});
this.$watch("versionFilter", (value) => {
const url = new URL(window.location.href);
if (value.length > 0) {
url.searchParams.set("version", value);
} else {
url.searchParams.delete("version");
}
history.replaceState(null, "", url);
});
},
versionCompare(v1, v2) {
if (v1 === v2) {
return 0;
}
const v1parts = v1.split(".");
const v2parts = v2.split(".");
if (v1parts[0] > v2parts[0]) {
return 1;
}
if (v1parts[0] < v2parts[0]) {
return -1;
}
return v1parts[1] > v2parts[1] ? 1 : -1;
},
featureSupportedIn(feature, version) {
// Can't tell if feature is added
if (feature.added === null) {
return false;
}
// Feature is not yet added in this version
if (this.versionCompare(feature.added, version) === 1) {
return false;
}
// Feature is added, removal is not specified
if (feature.removed === null) {
return true;
}
// Feature is removed
if (this.versionCompare(feature.removed, version) <= 0) {
return false;
}
// Feature is added and not removed
return true;
},
featureIsDeprecatedIn(feature, version) {
return feature.deprecated !== null
&& this.versionCompare(feature.deprecated, version) <= 0;
},
featureIsRemovedIn(feature, version) {
return feature.removed !== null
&& this.versionCompare(feature.removed, version) <= 0;
},
featureSupportedClass(feature, version) {
// Feature is deprecated, but not removed
if (
this.featureIsDeprecatedIn(feature, version) &&
!this.featureIsRemovedIn(feature, version)
) {
return "bg-amber-200";
}
return this.featureSupportedIn(feature, version)
? "bg-green-300 font-bold"
: "bg-red-300";
},
filteredFeatures() {
return this.changesInVersion(this.versionFilter, this.featuresHaving(this.searchString));
},
featureMatches(feature, keyword) {
keyword = keyword.toLowerCase();
return (
feature.name.toLowerCase().includes(keyword) ||
feature.description.toLowerCase().includes(keyword) ||
feature.keywords.some((featureKeyword) =>
featureKeyword.toLowerCase().includes(keyword)
)
);
},
featuresHaving(featureKeyword) {
return this.features.filter((feature) =>
this.featureMatches(feature, featureKeyword)
);
},
changesInVersion(version, features) {
return features.filter((feature) =>
! version ||
feature.added === version ||
feature.deprecated === version ||
feature.removed === version
);
},
/*
* This does some basic formatting.
*
* - backticks are converted to <code></code>
*/
formatAsHtml(rawString) {
// Code blocks denoted by backticks
tempString = rawString.replace(/`([\s\S]*?)`/g, "<code>$1</code>");
// Change double newlines to pararaphs
tempString = tempString.replace(/(?:[\r\n|\r|\n]{2})/g, '</p><p class="mb-4">');
// Change single newlines to line breaks
tempString = tempString.replace(/(?:\r\n|\r|\n)/g, '<br>');
// Wrap the outer with paragraphs
return '<p class="mb-4">' + tempString + '</p>';
},
};
});
});
</script>
</body>
</html>