-
Notifications
You must be signed in to change notification settings - Fork 0
/
slug_converter.php
59 lines (41 loc) · 1.09 KB
/
slug_converter.php
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
<?php
function slugify($text)
{
// replace non letter or digits by -
$text = preg_replace('~[^\\pL\d]+~u', '-', $text);
// trim
$text = trim($text, '-');
// transliterate
$text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);
// lowercase
$text = strtolower($text);
// remove unwanted characters
$text = preg_replace('~[^-\w]+~', '', $text);
if (empty($text))
{
return 'n-a';
}
return $text;
}
$link = mysqli_connect("localhost", "user", "pass", "db");
/* check connection */
if (mysqli_connect_errno()) {
printf("Connect failed: %s\n", mysqli_connect_error());
exit();
}
$query = "SELECT link_id, link_name FROM et_links LIMIT 1000";
if ($result = mysqli_query($link, $query)) {
/* fetch associative array */
while ($row = mysqli_fetch_assoc($result)) {
echo '<pre>';
$slug = slugify($row['link_name']);
echo $slug;
$sql = "UPDATE et_links SET link_internal_name ='".$slug."' WHERE link_id =".$row['link_id'];
mysqli_query($link, $sql);
}
/* free result set */
mysqli_free_result($result);
}
/* close connection */
mysqli_close($link);
?>