Sublime Forum

Php indent problem

#1


I have auto indent problem. Its happening on function.

0 Likes

#2

What is the problem you’re having? Please provide a detailed explanation so that other’s may understand and try to help you.

0 Likes

#3


left image is true indent but right image is bad indent.

0 Likes

#4

how can i do good indent like left image?

0 Likes

#5

so the string containing html causes the problem? does this happen while typing, or while using the Reindent functionality or both? can you paste the code here as text so we can try reproducing this behavior ourselves?

0 Likes

#6

its happening when i use this command
{“keys”: [“alt+shift+f”], “command”: “reindent”, “args”: {“single_line”: false}},

btw my code;
function giris($sorgu){
$query=$this->db->prepare(“SELECT * FROM kullanicilar WHERE email=’”.$sorgu[“email”]."’ and sifre=’".md5(trim($sorgu[“sifre”]))."’ “);
$query->execute();
$result=$query->fetch(PDO::FETCH_ASSOC);
if($query->rowCount()>0){
$_SESSION[“kullanici_bilgileri”]=$result;
$_SESSION[“kullanici_bilgileri”][“ad_soyad”]=$result[“ad”].” “.$result[“soyad”];
$this->swal(“Başarıyla giriş yapıldı”,“success”);
echo "";
}else{
$this->swal(“E-Mail veya Şifre Yanlış!”,“error”);
}
}

0 Likes

#7

help :confused:

0 Likes

#8

it’s kinda fixable by editing the indentation rules for PHP (i.e. using https://packagecontrol.io/packages/PackageResourceViewer) to ensure they apply to strings:

--- Shipped Packages/PHP/Indentation Rules.tmPreferences    2019-01-18 12:17:50
+++ Packages/PHP/Indentation Rules.tmPreferences    2019-11-01 21:13:19
@@ -4,21 +4,21 @@
    <key>name</key>
    <string>Indentation Rules</string>
    <key>scope</key>
-   <string>source.php - comment - meta.embedded.html - string, meta.html-newline-after-php</string>
+   <string>source.php - comment - meta.embedded.html, meta.html-newline-after-php</string>
    <key>settings</key>
    <dict>
but then your whole string will be have the same indentation level except inside the function, so I guess you may want to tweak the regex patterns some:

<?
function giris($sorgu){
    $query=$this->db->prepare(“SELECT * FROM kullanicilar WHERE email=’”.$sorgu[“email”]."’ and sifre=’".md5(trim($sorgu[“sifre”]))."’ ");
    $query->execute();
    $result=$query->fetch(PDO::FETCH_ASSOC);
    if($query->rowCount()>0){
        $_SESSION[“kullanici_bilgileri”]=$result;
        $_SESSION[“kullanici_bilgileri”][“ad_soyad”]=$result[“ad”].” “.$result[“soyad”];
        $this->swal(“Başarıyla giriş yapıldı”,“success”);
        echo "<script>
        setTimeout(function(){
            window.location.href
        }, 2000);
        </script>";
    }else{
        $this->swal(“E-Mail veya Şifre Yanlış!”,“error”);
    }
}
sidenote: probably you should improve your sql query code so you aren't vulnerable to sql injection - use parameters rather than quoting the strings. It's also better for performance in most DB engines.
0 Likes

#9

THANKS it worked but same problem on comment strings :frowning:

image

Can i do something for this ?

0 Likes

#10

i find you in github. thank you bro <3

0 Likes

#11

in fact, php indentation in Sublime a little “buggy”


it’s a really bad code, but I work with those kind of a code quite often:)

and I can’t find a good formater for php, maybe someone can suggest some ?
I had try few packages, but they work a little strange(for example some of them save file twice, so ctrl+z not work after formatting, e.t.c). Maybe someone can suggest something,)

0 Likes