Skip to content
Advertisement

Tag: string

How to get intersection between two strings in PHP

A problem description: I have two strings and I need to find the length of intersection of them. Let’s assume the both strings are Latin-ASCII and lower case. These are expected results: My try to solve the problem: I’ve tried to compare the strings using array_intersect() function this way: But this way of comparing two strings is inappropriate because it

extract numbers from a string if they meet a specific condition [closed]

Closed. This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 5 months ago. Improve this question In the following string there are some numbers followed by two letters “ST”. How can I extract all of those

Extract a YYYmmDD in PHP

I have images and videos from my camera which are uploaded to my server. In order to properly organize them I need to extract the year month and day. But I cant seem to get this pregmatch right.. Input would be 20211215_083437.jpg Output would be Year2021 Month11 Day15 Answer You need to remove the $ anchor in your RegEx to

strange question about PHP convert string to int

im trying to convert string to integer but return 0 or wrong number. Below is the code i have tested. Anyone know why? Thanks return integer 85 0 0 Answer By default, intval() parses base 10, so it ignores the 0x prefix. If you specify the base as 0, it will determine the base dynamically from the string prefix: 0x

Format integer or string in php

sorry for a noob question but I am wondering if you could format strings in php with comma or dashes, something like this: Ex. #1 Ex. #2 If anyone could help me out, that would be appreciated. Answer You could use a regex replacement here:

Advertisement