Skip to content
Advertisement

Tag: string

How to get some part of text from a large text

Is there any way to get get a small part of data from an array index in php? For example, I have an array of data like: Array( [title] => My title [description] =>Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry’s standard dummy text ever since the 1500s, when an

Get the last word of a string

I have tried a few things to get a last part out I done this: The first one won’t work and the second returns an array but a realy need string. Answer If you’re after the last word in a sentence, why not just do something like this? I wouldn’t recommend using regular expressions as it’s unnecessary, unless you really

How to call a function in a string using PHP

I wrote a function to dynamically insert the default date in a drop down option tag. In my function called pickDate I echo out the string at the end with double quotes. Then later in my code I have a for loop that produces a new string and inside the string I am trying to call my function. My problem

PHP Cleaning special characters from string

so I made this scraper and it returns strings from multiple sites. I want to check if the strings match, so I use php to clean the string and check. However, the & and other special characters appear in 2 ways, one as & and the other as &. How do I go about removing each type. I already have

How can I replace a variable in a string with the value in PHP?

I have string like this in database (the actual string contains 100s of word and 10s of variable): I echo this string like this: My output is I am a {$club} fan. I want I am a Barcelona fan. How can I do this? Answer Use strtr. It will translate parts of a string. For multiple values (demo): Program Output:

PHP Function to return string

I am fairly new to PHP. I have a function which checks the cost of price. I want to return the variable from this function to be used globally: Answer You should simply store the return value in a variable: The $deliveryPrice variable above is a different variable than the $deliveryPrice inside the function. The latter is not visible outside

How to determine max length of a certain array column?

The array looks like this: Can I determine the longest string length of the 3rd column, without having to iterate over the array? In my example the longest string would be “FooBar” – 6 chars. If the inner array had only the string element, I could do max(array_map(‘strlen’, $arr)), but it has 3 items… Answer Add array_map(‘array_pop’, $arr) to the

Advertisement