I have the local file path as c:\new folder\pdf\today\k.pdf I want to replace the c:\ with file:\\c|
I tried str_replace('','',) but I get error due to the slash, no stripslash will not work.
Thanks
Jean
Isn't c:\new folder\pdf\today\k.pdf to file:///c|new folder/pdf/today/k.pdf?
If so, following will work, without regex
$x='c:\new folder\pdf\today\k.pdf';
$x='file:///'.str_replace('\\','/',str_replace(':\\','|',$x));
file:///c|new folder/pdf/today/k.pdf will return
Try:
$string = 'c:\new folder\pdf\hello.pdf';
$new_str = str_replace("c:\\", "file:\\\\\\c|", $string);
echo $new_str;
Result:
file:\\\c|new folder\pdf\hello.pdf
You can do this:
<?php
$a = 'c:\new folder\pdf\today\k.pdf';
$a = str_replace('c:\\','file:\\\\\\c|',$a);
var_dump($a); // print string(36) "file:\\\c|new folder\pdf\today\k.pdf"
?>
Related
I want to replace all special character (in array), I used htmlspecialchars, but it does not work I found empty result !!
this is my instruction:
str_replace( array('è','é','ê','ë'),
array('e','e','e','e'),
htmlspecialchars(strtolower("Elément")) );
thank's for helping...
Short answer: you must use mb_strtolower instead strtolower,
run the snippet below you will find why:
<?php
$a = str_replace( array('è','é','ê','ë'), array('e','e','e','e'), htmlspecialchars(strtolower("Elément")) );
echo "\n0.".$a;
echo "\n1.".htmlspecialchars(strtolower("Elément"));
echo "\n2.".strtolower("Elément");
echo "\n3.".mb_strtolower("Elément");
echo "\n4.".htmlspecialchars(mb_strtolower("Elément"));
$a = str_replace( array('è','é','ê','ë'), array('e','e','e','e'), htmlspecialchars(mb_strtolower("Elément")) );
echo "\n5.".$a;
see also enter link description here
You could use a slugger, such as https://packagist.org/packages/javiereguiluz/easyslugger
I wrote a short test code in PHP7:
<?php
$str1=' bigapple ';
echo strlen($str1);
trim($str1) ;//or trim($str1," ")
echo strlen($str1);
?>
But whenever I use trim on $str1 ,the strlen would be return 10.
Can someone tell me the reason why? I've been searching it but find nothing.
You need to store trim string to any variable or you need to print trim string as following:
echo strlen(trim($str1));
You have not assigned the trimmed value in another variable. Try as below :
<?php
$str1=' bigapple ';
echo strlen($str1).'<br>';
$str2 = trim($str1);
echo strlen($str2).'<br>';
?>
I have a string that looks like this
$t="<b>vist</b>thank you for the follow.";
I am trying to remove the tag b and put an "#" instead of this tag.
I tried this
str_replace("<b></b>","#",$t);
but it doesn't replace the closing tag.
I don't know why it is not working may be there is something omitted in the code.
Try with
$search = array('<b>','</b>');
$replace = '#';
echo str_replace($search, $replace, $t);
To replace multiple words using str_replace() function,
You can Try this
$t="<b>vist</b> thank you for the follow";
$pattern=array();
$pattern[0]="<b>";
$pattern[1]="</b>";
$replacement=array();
$replacement[0]="#";
$replacement[1]="";
echo str_replace($pattern,$replacement,$t);
View the Demo
Try with -
$t="<b>vist</b>";
echo str_replace(array("<b>", "</b>"),"#",$t);
I have a string in the pattern similar to:
john.smith 9.5 9.49296 Active john.s#site.com +123456789
and I just want to echo "9.5" out of it which is next to "smith" using PHP.
Update:
sorry guys...just noticed that it is an xml file, couldn't see properly in safari, checked in firefox and it is displayed as:
<GetUserInfo>
<Customer>john.smith</Customer>
<Balance>9.5</Balance>
<SpecificBalance>9.49296</SpecificBalance>
<Status>False</Status>
<EmailAddress>john.s#site.com</EmailAddress>
<Phone>+1234567890</Phone>
</GetUserInfo>
Now what would be the php code to echo "9.5"
Thanks for your earlier answers...
Try splitting on whitespace (seem to be delimited by that)
$parts = preg_split('/\s+/', $input);
print $parts[1];
a quick and durty way
<?php
$string="john.smith 9.5 9.49296 Active john.s#site.com +123456789";
$array = explode(" ",$string);
echo $array[1];
?>
$string="john.smith 9.5 9.49296 Active john.s#site.com +123456789";
$array=explode(" ",$string);
Then your number would be:
echo $array[1];
This will work
<?php
$string = "<GetUserInfo>
<Customer>john.smith</Customer>
<Balance>9.5</Balance>
<SpecificBalance>9.49296</SpecificBalance>
<Status>False</Status>
<EmailAddress>john.s#site.com</EmailAddress>
<Phone>+1234567890</Phone>
</GetUserInfo>";
$xml = simplexml_load_string($string);
echo $xml->Balance;
?>
link is : info.php?Submit=#img.png
so
<?php echo $_GET["Submit"]; ?>
but this wil show : #img.png
how to remove the "#" from the name so it shows : img.png ??
thanks
$_GET["Submit"] will not contain that, since # marks the beginning of the 'fragment', which does not get passed to the server.
If the link is info.php?Submit=%23img.png, then you can trim it like this:
<?php echo substr($_GET["Submit"], 1); ?>
Well, you could always modify the sender code to exclude the leading # (or %23 as #Cal pointed out).
Otherwise, try one of these:
//substring [1:len]
$yourString = substr($_GET["Submit"], 1);
//replace "#" with ""
$yourString = str_replace("%23", "", $_GET["Submit"], 1); //1 is the limit of #s to remove
//parse the URL, then get the path
$yourString = parse_url($_GET["Submit"], PHP_URL_PATH);
Try this, if you are sure that the first character is either a # or the encoding of one (%23):
<?php echo substr(urldecode($_GET["Submit"]),1); ?>