36

I wanted to read about ?? in PHP.

I searched, https://stackoverflow.com/search?q=%3F%3F.

It returns 0 results.

But there are good questions, like C#'s null coalescing operator (??) in PHP, about ?? in PHP.

So can you please enable "symbol" search also.

9
  • 5
    This used to be possible, but it broke at some point
    – user247702
    Feb 23, 2018 at 12:06
  • 2
    @Stijn: Searching for code:"??" works for me, though.
    – honk
    Feb 23, 2018 at 12:12
  • 2
    @jonrsharpe Nope, what the answer suggests only searches in code blocks. What OP is asking here is supposed to work as I mentioned already.
    – user247702
    Feb 23, 2018 at 13:33
  • A feature request to change the current behavior doesn't seem like a dup of the "How to do X" when it is only a partial solution (like in this case) Feb 23, 2018 at 15:28
  • 3
    This has been broken for as long as Stack Overflow has existed. The problem was reported as early as during the private beta, way back when such reports where still on the uservoice site. It was briefly fixed around 2014, but has been broken again since circa 2015, with no acknowledgement by the dev team until now that it even is broken, let alone that they are working on fixing it. Feb 23, 2018 at 15:43
  • 1
    Google for "php double question mark site:stackoverflow.com" found the result you mentioned at about 4th one. And remembering the name of the 95 printable ASCII characters is not difficult.
    – user202729
    Feb 24, 2018 at 2:48
  • 1
    Alternatively, use SymbolHound. // But because people like "spamming" their question with ?s it doesn't really work well in this case. I hate those SO bad users. The first search result is not even an acceptable SO question nowadays.
    – user202729
    Feb 24, 2018 at 2:53
  • How would such a symbol search work with I need help??????? :-) Smiley aside, there are probably at least a few thousand questions on SO that contain ?? somewhere within them. How would a symbol search work with those? Or questions for C/C++/Java/Python/CountlessOthers for symbols like ++? (Oops! I used ++ when I wrote C/C++/Java - another useless symbol search result. Drat! Two more! Oh, wait... what about not ! in C/C++/Java/Python/JS/??)
    – Ken White
    Feb 24, 2018 at 5:31
  • SymbolHound, referenced in We need to be able to search for punctuation (symbols), has been dead since April 2022. May 28, 2022 at 17:17

3 Answers 3

11

Normal searches ignore special characters. To search for special characters, use the code operator, like so:

php code:"??"

While searching like this does occasionally run into issues (e.g. can't search for "), in this case it seems to work well enough. The question you are looking for is the fourth result.

See also my question: Why aren't we told we can use special characters in search?

8

As this is unlikely to get implemented I have created a query in the Stack Exchange Data Explorer to aid in these kind of searches.

Be warned that SQL Server without full-text indexes is having a hard time to find post with just a simple LIKE statement. That is why the query must be run on small sets, here achieved by insisting on selecting a tag. If the query times out, reduce the number of posts you want to include. Fork the query in that case and make your own adjustments.

Here is the query. It does try to escape the [, _ and % characters as those have special meaning in a LIKE operator within SQL Server. If something seems wonky try without any of those characters.

declare @symbolsearch nvarchar(200) = ##symbol:string##
declare @tag nvarchar(35) = ##tag:string?r##

set @symbolsearch = replace(@symbolsearch,'[', '[[]');
set @symbolsearch = replace(@symbolsearch,'_', '[_]');
set @symbolsearch = replace(@symbolsearch,'%', '[%]');

print @symbolsearch

;with tagposts as (
select p.id 
from posts p
inner join posttags pt on pt.postid = coalesce(p.parentid, p.id)
inner join tags t on t.id = pt.tagid
where tagname = @tag
),
posthistoryedits as (
  select ph.postid
       , max(ph.id) [latestid]
  from posthistory ph 
  inner join tagposts tp on tp.id = ph.postid
  where posthistorytypeid in (2,5)
  group by ph.postid
),
posthistorytext as (
  select ph.postid
       , ph.text
  from posthistory ph
  inner join posthistoryedits phe on phe.latestid = ph.id
)

select  top 50
       -- count(*)
       p.id as [Post Link]
     , p.posttypeid
     , p.score
     , p.creationdate
     , p.tags
from tagposts tp
inner join posts p on tp.id = p.id
inner join posthistorytext pht on pht.postid = p.id
where pht.text like concat('%', @symbolsearch, '%')
order by score desc

Here is an example of the output:

example output showing 16 post titles with score, creationdate and tags in the r tag with [<- as symbol

5
  • Looks hike that this only search for a single string instead of e.g. posts that contain both string A and string B? (by the way, for the purpose of this question, top 50 ordered by score is probably what the user want)
    – user202729
    May 28, 2022 at 0:55
  • @user202729 yes, it is only one search term. I'll add the order by in the query
    – rene
    May 28, 2022 at 7:20
  • Remark: It might be faster to query on p.body directly since it doesn't need the posthistory table, however if you do that you need to escape &lt; &gt; &amp; as well (not sure if there's anything else)
    – user202729
    Jun 16, 2022 at 15:10
  • @user202729 it will be faster but also useless. p.body contains the rendered html of the post so it has way more fluff in it. By only taking the markdown into consideration its less prone to having false positives and if you go to a post and hit edit you see exactly the text that was considered in the search. Using post.body would make diagnosing false positives way harder. I didn't go through the trouble finding the last revision in the posthistory because it was quick or easy but because I wanted the query to be somewhat useful.
    – rene
    Jun 16, 2022 at 17:29
  • Remark2: use concat(char(13), char(10)) to search for literal newline.
    – user202729
    Jun 17, 2022 at 0:40
-13

I wouldn't bother about symbol search. Especially question mark (=wildcard in most places!)

Spell it out instead... And use Google, filtering with site:stackoverflow.com:

https://www.google.com/search?q=php+double+question+mark+site%3Astackoverflow.com

Or you can pick up a definition and try a new search. In this case, "" helps,

php "null coalescing operator" site:stackoverflow.com

... read all about ?? in PHP, no problem.

4
  • 13
    This assumes there is a commonly accepted way to spell it out (be it akin to "double question mark" or more like "null coalescing operator"), and that the poster knows it or is otherwise able to guess it.
    – duplode
    Feb 24, 2018 at 19:13
  • 5
    @duplode: Otherwise resulting in lots of "I didn't know what to search for", it's true. Although it would be nice if people dropped their lazy reliance on quick searching: it is still possible to simply read the manual page on operators to find out what things do. Sadly the will to actually study has gone the way of the dinosaur; peeps ain't happy unless they can find their answer on Page 1 of Google, or get somebody here to spend their time creating a custom one. Feb 25, 2018 at 13:45
  • @LightnessRacesinOrbit "peeps ain't happy unless they can find their answer on Page 1 of Google" actually, they ain't happy if the breadcrums that google shows them is the actual answer
    – Braiam
    Feb 25, 2018 at 17:36
  • @Braiam: Gah! :( (lol) Feb 25, 2018 at 17:40

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .