Posts

Showing posts with the label string

Get File Refer Without File Extension Inward Php

Definition in addition to Usage - basename() The basename() component division returns the filename from a path. Syntax basename(path,suffix) Parameter Description path Required. Specifies the path to check suffix Optional. Specifies a file extension. If the filename has this file extension, the file extension volition non show Example <?php $path = "/testweb/home.php"; //Show filename amongst file extension echo basename($path) ."<br/>"; //Show filename without file extension echo basename($path,".php"); ?> The output of the code inwards a higher identify volition be: home.php home You convey to know the extension to take it inwards advance though. You tin laissez passer the sack exercise pathinfo() in addition to basename() together if you lot don't know the extension of the file. First cash inwards one's chips the extension using pathinfo(), in addition to exercise the basename function, si...

How To Take Away Final Comma From The Goal Of String Inwards Php?

If yous desire to take the comma from the cease of a string, yous tin role diverse tricks. But 1 elementary line a fast 1 on is to role PHP inbuilt constituent rtrim(). The rtrim constituent (and corresponding ltrim() for left trim) is real useful every bit yous tin specify a make of characters to remove. rtrim() strips whitespace (or other characters) from the cease of a string. Example: $string = "Hello, I, am, Anup,"; echo $string = rtrim($string, ','); //it volition take a char if the final char is a comma //output : "Hello, I, Am, Anup"; If yous desire to take precisely 1 comma, which may or may non survive there, use: if (substr($string, -1, 1) == ',') { $string = substr($string, 0, -1); } Sumber http://developer-paradize.blogspot.com

Create Array Without Keys From Comma Separated String Using Php

You can't convey an array without keys. But at that spot is workaround to become inwards possible. Grab the comma separated string together with piece of job explode business office to practise array. Use the implode business office on resulting array, together with you lot volition become the overnice array without keys. Example $strings = "my, name, is, Anup"; $arraydata = explode(",", trim($strings)); echo '$arr = array("'.implode('", "', $arraydata).'");'; //output // $arr = array("my", "name", "is", "Anup"); Sumber http://developer-paradize.blogspot.com