PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Sunday, November 20, 2022

[FIXED] why do arrows < break this regex?

 November 20, 2022     php, preg-replace, regex     No comments   

Issue

$str = "for(var i = 0; i < aLinks.length; i++) {"; 

preg_replace( "!\s+!", "", $str  );

output: for(vari=0;i

My desired output is

for(var i=0;iaLinks.length;i++){

if I remove the arrow like this $str = "for(var i = 0; i (no arrow here) aLinks.length; i++) {"; then I get the desired output.

Why does the back arrow break the regex?

What I want the regex to do is remove all tabs line breaks and spaces and nothing else. the strings may have operators like < or > etc and I want these to be ignored.


Solution

This was a stupid school boy error. I was viewing the output in a browser so it was interpreting the "<" as a tag and everything after that was invisible. Simply viewing the source in the browser showed it was actually working exactly as expected.



Answered By - Feels Unique
Answer Checked By - Clifford M. (PHPFixing Volunteer)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing