1137 gün önce Unsplash gibi yerden resim çekme php
sorusunu cevapladı.
<?php
// $_GET['q'] ile aranan değere uygun unsplash.com'dan resim getiren fonksiyon
function get_image($q)
{
$url = "https://source.unsplash.com/featured/?" . $q; // resim url'si
$ch = curl_init(); // curl başlat
curl_setopt($ch, CURLOPT_URL, $url); // url ayarla
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); // çıktıyı döndür
$output = curl_exec($ch); // çıktıyı al
$info = curl_getinfo($ch); // bilgileri al
curl_close($ch); // curl kapat
return $info['url']; // resim url'sini döndür
}
// $_GET['q'] değeri yoksa varsayılan olarak "nature" gönderiyoruz
$q = isset($_GET['q']) ? $_GET['q'] : "nature";
// kullanıcıdan arama değeri alıyoruz
$searchParam = htmlspecialchars($q);
// arama değerine göre resim getiriyoruz
$image = get_image($searchParam);
// resmi ekrana yazdırıyoruz
echo '<img src="' . $image . '" alt="' . $searchParam . '" />';
1137 gün önce Butona Tıklayarak js deki String Metni Kopyalamak
sorusunu cevapladı.
<!-- html -->
<button type="button" id="copyText">Veri'yi Getir</button>
<div id="string"></div>
<!-- copyText butonuna tıklandığında, string id'li div'in içine let message içindeki veriyi yaz -->
<!-- javascript -->
<script>
let message = "Merhaba Dünya";
let copyText = document.getElementById("copyText");
let string = document.getElementById("string");
copyText.addEventListener("click", function() {
string.innerHTML = message;
});
</script>
1137 gün önce File input'dan dosya ismini text inputa gösterme post etmeden
sorusunu cevapladı.
<!-- file form oluştur -->
<form action="#" method="post" enctype="multipart/form-data">
<input type="file" name="file">
<input type="text" name="file_name">
<button type="submit" name="submit">Yükle</button>
</form>
<!-- js ile file input'tan dosya adını parçala ve text inputuna yaz -->
<script>
const fileInput = document.querySelector('input[type="file"]'); // file input
const textInput = document.querySelector('input[name="file_name"]'); // text input
fileInput.addEventListener('change', () => { // file input'ta değişiklik olduğunda
let fileName = fileInput.value.split('\\'); // file input'tan dosya adını parçala
fileName = fileName[fileName.length - 1]; // parçalanan dosya adını
textInput.value = fileName; // text input'a yaz
});
</script>
1137 gün önce php para birimi kontrolü
sorusunu cevapladı.
<?php
function checkPrice($price)
{
$price = (float) $price;
if ($price > 0 && $price < 9999999.99) {
return $price;
} else {
return false;
}
}
// kullanım örneği
$price = checkPrice(123.45);
if ($price) {
echo $price;
} else {
echo 'Hatalı fiyat';
}
// sonuç: 123.45
1138 gün önce Cümle İçerisinde Arama
sorusunu cevapladı.
<?php
// bir json dosyasındaki anahtarın değerine göre arama işlemi yapan sınıf
class Filter
{
// json dosyası
private $jsonFile = 'filter_arr.json';
// json dosyasındaki anahtarın değerine göre arama işlemi
public function searchAndReturnJson($search)
{
// json dosyasını oku
$json = file_get_contents($this->jsonFile);
// json dosyasını diziye çevir
$array = json_decode($json, true);
// dizi içinde arama yap
$result = $this->search($array, $search);
// sonuç varsa json olarak döndür
if ($result) {
return json_encode($result);
}
// sonuç yoksa false döndür
return false;
}
// dizi içinde arama işlemi
private function search($array, $search)
{
// dizi içinde dolaş
foreach ($array as $key => $value) {
// anahtarın değeri aranan değerse
if ($value == $search) {
// anahtarın değerini döndür
return $value;
}
// anahtarın değeri dizi ise
if (is_array($value)) {
// dizi içinde arama yap
$result = $this->search($value, $search);
// sonuç varsa
if ($result) {
// sonucu döndür
// return $result;
return true;
}
}
}
// sonuç yoksa false döndür
return false;
}
}
// kullanım örneği:
require_once 'Filter.php'; // Filter sınıfını kullanacağın sayfaya dahil et
$filter = new Filter(); // sınıfı oluştur
$response = $filter->searchAndReturnJson('******'); // arama işlemi
if ($response) { // sonuç varsa
echo $response; // sonucu ekrana yazdır
} else { // sonuç yoksa
echo 'Sonuç bulunamadı'; // mesaj yazdır
}
1433 gün önce svg hakkında
sorusunu cevapladı.
google ikonlarına alternatif linkler:
https://fontawesome.com/v5.15/icons
https://linearicons.com/free
https://www.flaticon.com/uicons
https://ionic.io/ionicons
1770 gün önce php ile telegram botu
sorusunu cevapladı.
Aynı hatayı bende alıyordum...
Söyle çozdüm:
01- Şu kısım yerine
// echo $telegram->setWebhook('https://kodogren.requestcatcher.com/');
02- Böyle yaz sonra websiteni yenile
echo $telegram->setWebhook('https://domanin_adresin.com/telegram.php');
sonra kodu tekrar pasif yap
- Bunu yapman webhook adresini değiştirecektir
DİPNOT: Local'de kod çalışmaz !