I got the following color -16777216 and I want to convert it to a alpha-hex code like this 00FFBBCC in PHP. I also want to be able to do the reverse. I really don't know where to start and my friend Google has no answer for me.
Any one can help please ?
Thank you.
What about using dechex()?
echo dechex(-16777216);
It outputs ff000000
If you want uppercase letters, simply use strtoupper():
echo strtoupper(dechex(-16777216)); //FF000000
Edit: to do the reverse, use hexdec() instead of dechex()
Related
My example code is given below.
$a= "I think there are many people who can help in my difficulty. breakword Thank you in advance. brwakword If i got this solution I will be happy. Breakword I have already searched in google about it I did not get it's solution. Breakword If you have any link of solution please help me. breakword Thank you again!";
From the above string I want to get the sentence between 2nd and 3rd 'breakword' word.
It means I want to extract 'If i got this solution I will be happy.'.
If you have any solution please help me. Thank you in advance
You can split your string into smaller parts using explode() and get the "Nth" part of the array.
$sentences = explode('breakword', $a);
echo $sentences[2];
PHP > 5.4 will support this too :
echo explode('breakword', $a)[2];
a similar approach but intead of using explode you can also use preg_split
supports (PHP 4, PHP 5)
preg_split('/breakword/', $a);
for the second answer you can use
$dummy=array();
preg_match_all('/breakword/', $a,$dummy)
in PHP I have the following case:
<?php $anz1='3';$i='1';echo $anz.$i;?>
I don't know how to echo $anz1 with the help of $i. I must do it this way, this is just an easy case, I need it for loops where it echos every $anz
Thanks in advance
I hope I could write it understable for you, my english is not the very best.
Maybe this is what you're looking for:
$anz1='3';
$i='1';
echo ${'anz'.$i};
Output:
3
yeah, I know, the title is kind of confusing, but no better title came to my mind.
Here is my problem:
I want to use a link in my application, which would look like this:
localhost/index?jumpto=some_folder/somescript.php?someparam1=1234&someparam2=4321
The problem is that &someparam2 is meant to hang on the second $_GET-Param.
It would be like this:
localhost/index?jumpto=some_folder/somescript.php?someparam1=1234&someparam2=4321
Instead, PHP interprets that &someparam2 hangs on the first $_GET-Param.
localhost/index?jumpto=some_folder/somescript.php?someparam1=1234&someparam2=4321
Does anyone know a solution for this?
I already tried
localhost/index?jumpto='some_folder/somescript.php?someparam1=1234&someparam2=4321'
but of course that didn't work.
I hope you can understand my problem.
Thank you for your time.
You will need to URL encode your string some_folder/somescript.php?someparam1=1234 so that php will not parse & in the query string as a param separator.
use urlencode("some_folder/somescript.php?someparam1=1234");
I've tried to create a code in PHP that gets the topic id after the forward slash in a given string. However the problem i'm having is that its returning nothing, how can i make it return the int?
echo preg_match('/([^/]+)/', 'Learning-English/478', $discussion_id);
echo $discussion_id;
This is for an online forum, thank you for your help; it's much appreciated. If you need ay more information please don't hesitate to leave a comment.
preg_match("#/(\d+)$#", 'Learning-English/478', $discussion_id);
That would work for you.
To print the id(matched number); you need to echo $discussion_id[1].
Here is a working link.
For the newer strings, you wouldn't be needing the string end match($). Thus, the regex will be:
preg_match("#/(\d+)#", 'Looking-for-Pen-Pals/1161&t=viewDiscussion', $discussion_id);
echo $discussion_id[1];
you could just use explode() like this:
$arr = explode('/',$string);
$discussion_id = $arr[count($arr)-1];
this will split your string and then get you the last part.
I'm using wordpress. I remember messing with the code of <?php the_time('d.m.y') ?> and getting something like "2011161457" (2011 16-1 4:57) I don't remember how I did it. I want just the numbers anyone knows how to do it?
Look at the PHP date() man page. Wordpress's time_time() is basically just a wrapper around that and uses the exact same formating options.