Questions tagged [phpjs]

Open source library which brings much of the PHP function API to JavaScript

php.js is a dual-licensed JavaScript library (MIT or GPL) which brings parts of the large PHP function library to JavaScript with the aim of providing commonly needed utilities and a familiar syntax to PHP developers.

The tag might also be used for anyone seeking to implement PHP functions or features in JavaScript regardless of whether the library currently has such an implementation.

35 questions
273
votes
21 answers

JavaScript equivalent of PHP's in_array()

Is there a way in JavaScript to compare values from one array and see if it is in another array? Similar to PHP's in_array function?
roflwaffle
  • 29,590
  • 21
  • 71
  • 94
84
votes
2 answers

nl2br() equivalent in javascript

Possible Duplicate: jQuery convert line breaks to br (nl2br equivalent) Currently I add
for each evt.which == 13. Is there a nl2br() for JavaScript, so I can do away with this evt.which == 13? How different is this from…
X10nD
  • 21,638
  • 45
  • 111
  • 152
71
votes
9 answers

Javascript equivalent of PHP's list()

Really like that function. $matches = array('12', 'watt'); list($value, $unit) = $matches; Is there a Javascript equivalent of that?
Markus Hedlund
  • 23,374
  • 22
  • 80
  • 109
19
votes
5 answers

preg_match_all JS equivalent?

Is there an equivalent of PHP's preg_match_all in Javascript? If not, what would be the best way to get all matches of a regular expression into an array? I'm willing to use any JS library to make it easier.
Alex S
  • 25,241
  • 18
  • 52
  • 63
15
votes
3 answers

JavaScript equivalent of PHP preg_split()

Is there an equivalent of the PHP function preg_split for JavaScript?
Randomblue
  • 112,777
  • 145
  • 353
  • 547
13
votes
8 answers

uniqid() in javascript/jquery?

what's the equivalent of this function in javascript: http://php.net/manual/en/function.uniqid.php Basically I need to generate a random ID that looks like: a4245f54345 and starts with a alphabetic character (so I can use it as a CSS id)
Alex
  • 66,732
  • 177
  • 439
  • 641
7
votes
3 answers

Equivalent Javascript substr_count?

I am trying to find an equivalent function for Javascript. What I am trying to do is look for the current URL and if it has the following first part of the URL then do something. In PHP I have this if (substr_count($current_url, $root .…
user381800
6
votes
2 answers

javascript equivalent to php unpack() function

I am looking for the javascript equivalent of php unpack() function? can someone direct me please. Thanks!
jazz
  • 143
  • 1
  • 3
  • 8
6
votes
3 answers

strptime in Javascript

I have a date input field that allows the user to enter in a date and I need to validate this input (I already have server side validation), but the trick is that the format is locale dependent. I already have a system for translating the strptime…
mpeters
  • 4,737
  • 3
  • 27
  • 41
4
votes
3 answers

JavaScript construct equivalent to PHP's list()?

Possible Duplicate: Javascript equivalent of PHP's list() In PHP you can do assignment like this: list($b,$c,$d) = array("A","B","C"); Is there anything like that in JS?
Bill Software Engineer
  • 7,362
  • 23
  • 91
  • 174
4
votes
1 answer

WordPress Malware - Redirect to (fast.destinyfernandi.com) - even after scan and clean

I'm living my worse nightmare. I have an CentOS server, that is hosting 10s of WordPress website. My clients notice that their websites are opening and after loading it is redirected to (fast.destinyfernandi.com) <---- Malware website. I used ClamAV…
4
votes
4 answers

How can I use preg_match in jQuery?

Can I use preg_match to validate phone number in jQuery? Here is my code which does not work: if (!preg_match("/^[0-9]{3}-|\s[0-9]{3}-|\s[0-9]{4}$/", phone.val() )) { phone.addClass("needsfilled"); phone.val(phonerror); …
Mary
  • 355
  • 4
  • 9
  • 17
4
votes
6 answers

array_count_values for JavaScript instead

I have the following PHP-script, now I need to do the same thing in JavaScript. Is there a function in JavaScript that works similar to the PHP function, I have been searching for days but cannot find anything similar? What I want to do is to count…
user626342
  • 147
  • 3
  • 11
4
votes
6 answers

str_shuffle() equivalent in javascript?

Like the str_shuffle() function in PHP, is there a function similar in shuffling the string in javascript ? Please help !
Aakash Chakravarthy
  • 10,523
  • 18
  • 61
  • 78
4
votes
2 answers

Javascript equivalent of php's parse_url

I am writing a chrome extension that change part of the url in the current tab and reload the page with the modified url. I am wondering if there is a Javascript equivalent of the php's parse_url function. Currently, I have to write my own parser…
defoo
  • 5,159
  • 11
  • 34
  • 39
1
2 3