substr

PHP, substr symbols from the end

Hello ... There are number '2352362361 ', as it is separated by spaces from the end of 3 characters? The output should obtain '2 352 362 361 ' ...

Using PHP substr() and strip_tags() while retaining formatting and without breaking HTML

I have various HTML strings to cut to 100 characters (of the stripped content, not the original) without stripping tags and without breaking HTML. Original HTML string (288 characters): $content = "<div>With a <span class='spanClass'>span over here</span> and a <div class='divClass'>nested div over <div class='nestedDivClass'>there</di...

Unix substr in shell script?

I have a string like sample.txt.pgp and I want to return sample.txt in a shell script (but, the string length will vary, so, basically all of the characters before the ".pgp"). Is there a substr function? Like, if I did substr('sample.txt.pgp', -4, 0), is it supposed to return sample.txt? Right now it isn't, so I'm wondering if I have...

How to get a substring in awk

This is one line of the input file: FOO BAR 0.40 0.20 0.40 0.50 0.60 0.80 0.50 0.50 0.50 -43.00 100010101101110101000111010 And an awk command that checks a certain position if it's a "1" or "0" at column 13 Something like: awk -v values="${values}" '{if (substr($13,1,1)==1) printf values,$1,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13}' fo...

What is the equivalent of REGEXP_SUBSTR in mysql?

I want to extract a word from a string column of a table. description =========================== abc order_id: 2 xxxx yyy aa mmm order_id: 3 nn kk yw Expected result set order_id =========================== 2 3 Table will at most have 100 rows, text length is ~256 char and column always has one order_id present. So performance is ...

How efficient is PHP's substr?

I'm writing a parser in PHP which must be able to handle large in-memory strings, so this is a somewhat important issue. (ie, please don't "premature optimize" flame me, please) How does the substr function work? Does it make a second copy of the string data in memory, or does it reference the original? Should I worry about calling, for...

Count occourances by hour in PHP

I have a script that polls a MySQL database (Nagios, specifically) for the date/time of events. I want to count how many events occur in each hour based upon all of the data my script returns. Here is what the results look like: (each on their own line) 2010-03-01 03:20:26 2010-02-28 19:07:26 2010-02-28 00:50:37 2010-02-27 17:07:35 ...

PHP limit text string NOT including html tags?

Here's what's NOT working for me: <?php $string = 'I have a dog and his name is <a href="http://www.jackismydog.com"&gt;Jack&lt;/a&gt; and I love him very much because he\'s my favorite dog in the whole wide world and nothing could make me not love him, I think.'; $limited = substr($string, 0, 100).'...'; echo $string; ?> I want to...

scrape email addresses

fff.html is an email with email addresses in it some have href mailto links and some don't, i want to scrape them and output them into the following format [email protected],[email protected],[email protected] I have a simple scraper to get the ones that are href linked but something is wierd <?php $url = "fff.html"; $raw = f...

Jquery/Javascript - store last 4 letters of string (cross browser)

Hi, I've written a quick image swap class that switches images on hover by placing adding '_grey' to the image src. The code works great throughout the site in all browsers apart from ie6. The substr doesnt seem to work properly here - any advice please!? Code as follows - $(document).ready(function() { var initImg; $('img.s...

Javascript substring() trickery

Hi folks I have a URL that looks like http://mysite.com/#id/Blah-blah-blah, it's used for Ajax-ey bits. I want to use substring() or substr() to get the id part. ID could be any combination of any length of letters and numbers. So far I have got: var hash = window.location.hash; alert(hash.substring(1)); // remove # Which removes th...

PHP: How to find the beginning and end of a substring in a string?

Hi, This is the content of one mysql table field: Flash LEDs: 0.5W LED lamps: 5mm Low Powers: 0.06W, 0.2W Remarks(1): this is remark1 ---------- Accessories: Light Engine Lifestyle Lights: Ambion, Crane Fun Office Lights: OL-Deluxe Series Street Lights: Dolphin Retrofits: SL-10A, SL-60A Remarks(2): this is remark2 ---------- Infrared R...

jQuery: substr method on link text?

hey guys, why is this not working? $("a.newslinks").each(function(){ if ($(this).text().length > 38) { $(this).text().substr(35); //does not work $(this).append('...'); //works $(this).css({ "color" : "#ff00cc" }); //works } }); if a link has its text longer than 38 characters i ...

PHP - Get part of string by searching for characters, instead of counting them?

With the substr() function i must enter where i want to cut the string by numbers, is there any way of cutting a string by passing words or characters? Something like this: <?php $string = "Hey there world!"; magic_substr($string, "there ", "!"); // returns "world" ?> Is there a function like that? If so, i've missed something ...

PHP substr after a certain char, a substr + strpos elegant solution?

Hello, let's say I want to return all chars after some needle char 'x' from: $source_str = "Tuex helo babe". Normally I would do this: if( ($x_pos = strpos($source_str, 'x')) !== FALSE ) $source_str = substr($source_str, $x_pos + 1); Do you know a better/smarter (more elegant way) to do this? Without using regexp that would no...

Converting a C (\0 terminated) string to a PHP string

PHP is one of those languages I use periodically, but usually have to dust the cobwebs off when I start using it again. The same applies this week whilst I port some C code to PHP. This uses a lot of AES encryption and SHA256 hashing - all working fine so far. However, decrypted strings come out in "C" form - i.e. terminated with a zero ...